Synopsis:
The list of options could be replaced by the corresponding OptionTable.
The methods installed for this method function should be written in the form opts -> args -> (...). The argument args will be assigned a hash table of type OptionTable containing the optional argument names and their current values. For example, in the body of the function, the current value for the argument named b can be recovered with opts#b, or with opts.b, in case b is known to be a global symbol. Warning: be careful not to change the value of b, or the code will stop working; it would be a good idea to protect it. The default option table for f can be recovered with the function options.
In this example we make a linear function of a single real variable whose coefficients are provided as optional arguments.
i1 : protect Slope; protect Intercept; |
i3 : f = method(Options => {Slope => 1, Intercept => 1}) |
i4 : f RR := o -> x -> o.Slope * x + o.Intercept |
i5 : f(5.) |
i6 : f(5.,Slope=>100) |
i7 : options f |
See also: