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

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

- Operator: SPACE
- Usage:
    `T x`
- Inputs:
  - T, a foreign struct type,
  - x, a hash table or a visible list,
- Outputs:
  - a foreign object,

## 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.141592653589793

    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:

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

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/ForeignFunctions.m2:1446:0.