next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc :: OptionTable >> Function

OptionTable >> Function -- attaching options to a function

Synopsis

Description

The new function g works as follows. The value of g args, say, is obtained by evaluation of (fun opts)(args'), where args' is obtained from args by removing the options of the form X=>A (where X is a name of an optional argument), and opts is a hash table of the same form as defs in which the default values have been replaced by the user-supplied values, e.g., the value stored under the key X has been replaced by A.

Remark: defs can also be simply a list of options.

In the following example we use a simple definition for fun so we can see everything that fun receives.

i1 : g = {a=>1, b=>2} >> opts -> args -> {args, opts}

o1 = g

o1 : FunctionClosure
i2 : g x

o2 = {x, OptionTable{a => 1}}
                     b => 2

o2 : List
i3 : g(x,y,b=>66)

o3 = {(x, y), OptionTable{a => 1 }}
                          b => 66

o3 : List
i4 : g(t,u,a=>44,b=>77)

o4 = {(t, u), OptionTable{a => 44}}
                          b => 77

o4 : List
i5 : h = true >> opts -> args -> {args, opts}

o5 = h

o5 : FunctionClosure
i6 : h(t,u,c=>55)

o6 = {(t, u), OptionTable{c => 55}}

o6 : List

See also