next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc > The Macaulay2 language > operators > ->

-> -- make a function


x -> e -- denotes a function. When the function is called, the initial value of the variable x is the argument if there is just one, or else is the sequence of arguments.
(x) -> e -- denotes a function of one argument. When the function is applied to an expression w three things may happen:
  • if w is not a sequence, then the initial value of x is w;
  • if w is a sequence of length one, then the initial value of x is the unique element of w; or
  • if w is a sequence of length other than one, then it is an error.

(x,y) -> e -- denotes a function of two arguments.

Similarly for more arguments.

These operations create what is usually called a closure, which signifies that the function remembers the values of local variables in effect at the time of its creation, can change those values, and share the changes with other functions created at the same time.

i1 : f = x -> 2*x+1

o1 = f

o1 : FunctionClosure
i2 : f 100

o2 = 201
The class of all functions is Function.

For the programmer

The object -> is a keyword.