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

ForeignStructType VisibleList -- cast a hash table to a foreign struct

Synopsis

Description

To cast a Macaulay2 hash table to a foreign object with a struct type, give the type followed by the hash table, or a list that could be passed to hashTable to create one. The keys should correspond to the keys of the hash table passed to foreignStructType when constructing T.

i1 : mystruct = foreignStructType("mystruct", {"foo" => int, "bar" => double})

o1 = mystruct

o1 : ForeignStructType
i2 : x = mystruct {"foo" => 5, "bar" => pi}

o2 = HashTable{"bar" => 3.14159}
               "foo" => 5

o2 : ForeignObject of type mystruct

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

i3 : x_"foo"

o3 = 5

o3 : ForeignObject of type int32
i4 : x_"bar"

o4 = 3.14159265358979

o4 : ForeignObject of type double

They may also be modified using subscripted assignment.

i5 : x_"foo" = 6

o5 = 6

o5 : ForeignObject of type int32
i6 : x

o6 = HashTable{"bar" => 3.14159}
               "foo" => 6

o6 : ForeignObject of type mystruct

Ways to use this method: