next up previous index
Next: InstallationTips and Up: Options Previous: Setting and Querying

Dynamic Options

  It is also possible to compute the value of an option dynamically: when the option value is a structure (not a list), it is not interpreted as the actual value option. Instead, Grace interprets it as a callable term used to compute the option value when it is being queried. The actual mechanism is similar to the evaluation of arithmetic functions inside is/2  : one argument is appended to the structure, the resulting term is called, and when it succeeds, the value of the additional argument is interpreted as the result of the evaluation, i.e. the option value. Variables which occur in the option window or name argument can be passed to the callable term, the option mechanism will instantiate them as expected when the goal is called.

The goal is by default called in the module, from which grace_start/1   was invoked. If the goal has the format Module:Goal, it will be called in the module Module.

For example, we may define the option show   for all variable matrices, so that small matrices will be by default displayed on the screen and large ones will not. This effect can be achieved by the following sequence in the .gracerc file:

:- grace_option(Matrix, show, on_if_small(Matrix)).

on_if_small(Matrix, Value) :-
    grace_option(Matrix, label_x, XL),
    grace_option(Matrix, label_y, YL),
    length(XL, Columns),
    length(YL, Rows),
    (Rows*Columns < 100 ->
        Value = on
    ;
        Value = off
    ).

We use the variable window argument for the option, so that it by default applies to any matrix. The matrix name is passed to the callable term in the value argument, and when the option value is queried, the goal on_if_small(Matrix, Value) is called. Inside this predicate we first obtain the size of the matrix via the sizes of its row and column labels. The variable Value is then bound depending on the number of elements in the matrix.



next up previous index
Next: InstallationTips and Up: Options Previous: Setting and Querying



Micha Meier
Tue Jul 2 10:07:34 MET DST 1996