[previous][up][top][index]
search for:

method(..., Options => ...) -- method functions with optional arguments

Synopsis:

  • Usage: f = method(Options => {a=>x, b=>y, ...})
  • Input:
  • {a=>x, b=>y, ...}: a list of names a, b, ..., for optional arguments with default values x, y, ... .
  • Output:
  • f: a method function that accepts optional arguments
  • 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})

    o3 = f

    o3 : Function
    i4 : f RR := o -> x -> o.Slope * x + o.Intercept

    o4 = --Function[stdio:3:3]--

    o4 : Function
    i5 : f(5.)

    o5 = 6.

    o5 : RR
    i6 : f(5.,Slope=>100)

    o6 = 501.

    o6 : RR
    i7 : options f

    o7 = OptionTable{Intercept => 1}
                     Slope => 1

    o7 : OptionTable

    See also:

  • Default value: null -- nothingness
  • Function: method -- make a new method function
  • Option name: Options

  • [previous][up][top][index]
    search for: