This function attempts to convert x to its corresponding Macaulay2 equivalent.
i1 : value rs "[1, 3.14159, 'foo', (1,2,3), {'foo':'bar'}]" o1 = {1, 3.14159, foo, (1, 2, 3), HashTable{foo => bar}} o1 : List |
i2 : class \ oo o2 = {ZZ, RR, String, Sequence, HashTable} o2 : List |
Since the type of x is not initially known, a sequence of hooks are used to determine its type and then convert it.
i3 : hooks value o3 = {0 => (value, PythonObject, Strategy => unknown -> PythonObject) } {1 => (value, PythonObject, Strategy => function -> FunctionClosure)} {2 => (value, PythonObject, Strategy => dict -> HashTable) } {3 => (value, PythonObject, Strategy => set -> Set) } {4 => (value, PythonObject, Strategy => list -> List) } {5 => (value, PythonObject, Strategy => tuple -> Sequence) } {6 => (value, PythonObject, Strategy => str -> String) } {7 => (value, PythonObject, Strategy => complex -> CC) } {8 => (value, PythonObject, Strategy => float -> RR) } {9 => (value, PythonObject, Strategy => int -> ZZ) } {10 => (value, PythonObject, Strategy => bool -> Boolean) } o3 : NumberedVerticalList |
If no conversion can be done, then x is returned.
i4 : rs "int" o4 = <class 'int'> o4 : PythonObject of class type |
i5 : value oo o5 = <class 'int'> o5 : PythonObject of class type |
Users may add additional hooks using addHook or the convenience function addPyToM2Function.