next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Python :: toFunction

toFunction -- convert callable python objects to Macaulay2 functions

Synopsis

Description

This function will convert a Python object into a Macaulay2 function.

i1 : math = import "math"

o1 = <module 'math' (built-in)>

o1 : PythonObject of class module
i2 : pysqrt = toFunction math@@sqrt

o2 = pysqrt

o2 : FunctionClosure
i3 : pysqrt 2

o3 = 1.4142135623730951

o3 : PythonObject of class float

Optional arguments can be provided using options.

i4 : int = toFunction rs "int"

o4 = int

o4 : FunctionClosure
i5 : int("deadbeef", "base" => 16)

o5 = 3735928559

o5 : PythonObject of class int

If a python object and a Macaulay2 thing are separated by a space, then toFunction will be called on the python object and then resulting function will be called with the Macaulay2 object as its argument.

i6 : math@@cos pi

o6 = -1.0

o6 : PythonObject of class float

Ways to use toFunction :

For the programmer

The object toFunction is a method function.