Macaulay2 » Documentation
Packages » ForeignFunctions :: foreignUnionType
next | previous | forward | backward | up | index | toc

foreignUnionType -- construct a foreign union type

Synopsis

Description

To construct a foreign union type, specify a name and a list of the members. Each member should be an Option of the form memberName => memberType, where memberName is a String and memberType is a ForeignType.

i1 : myunion = foreignUnionType("myunion",
         {"foo" => 4 * char', "bar" => charstar})

o1 = myunion

o1 : ForeignUnionType

Use _ to return a single member of a foreign union.

i2 : x = myunion (4 * char') append(ascii "hi!", 0)

o2 = HashTable{"bar" => hi!              }
               "foo" => {104, 105, 33, 0}

o2 : ForeignObject of type myunion
i3 : x_"foo"

o3 = {104, 105, 33, 0}

o3 : ForeignObject of type int8[4]
i4 : x_"bar"

o4 = hi!

o4 : ForeignObject of type char*

They may also be modified using subscripted assignment.

i5 : x_"bar" = "ho!"

o5 = ho!

o5 : ForeignObject of type char*
i6 : x

o6 = HashTable{"bar" => ho!              }
               "foo" => {104, 111, 33, 0}

o6 : ForeignObject of type myunion

Ways to use foreignUnionType :

For the programmer

The object foreignUnionType is a method function.