|
|
To obtain a descriptor value for the first time, FMLI must either use the default value of the descriptor, if any, or evaluate the expression coded for the descriptor. Expression evaluation resolves references to variables, removes quotes, and causes any backquoted expressions to be executed. Backquoted expressions may be used for their side effects only or may generate standard output that is used as part of the descriptor value.
By default, FMLI determines how often descriptors are evaluated. Most are evaluated only once, the first time the descriptor value is needed; the value of the descriptor remains the same throughout the life of the frame. This does not mean that the value cannot be used, or ``referenced,'' again, only that it will not be recomputed each time it is referenced.
Other descriptors are evaluated multiple times in the life of a frame. In these cases, all backquoted expressions coded as part of the descriptor are executed, for output and side effects, each time the descriptor is evaluated. Some of these descriptors are evaluated whenever they are referenced, others are evaluated only when referenced in certain conditions. The show descriptor, for instance, is typically used to make fields in a form appear or disappear based on values the user has entered in other fields. show is referenced when the form is opened and thereafter each time the user navigates between fields in the form. show is evaluated, however, only the first time it is referenced and thereafter only when the user has changed the value of a field before navigating away.
For performance reasons, then, FMLI evaluates descriptors only as necessary in the typical case. That may still be too often, or not often enough, for your application. In these situations, you can use the const type cast to make sure that a descriptor is evaluated only once, no matter how many times it is referenced, or the vary type cast to make sure that a descriptor is evaluated whenever it is referenced.
As an example of how you might use const, consider a form that contains a field that should only be completed on Friday. You can define the show descriptor for the field so that it will appear only when the date +%a command evaluates to Friday:
show=`set -l DAY=date +%a; test "$DAY" = "Friday"`In the example, the FMLI built-in utility set -l sets the local variable DAY to the output of the date +%a command.
The problem with this is that, by default, FMLI will evaluate show more times than is necessary for your application: not only when the form is opened, but whenever the user changes a value in a field and navigates to another field. To prevent that, you can use const as follows:
show=const `set -l DAY=date +%a; test "$DAY" = "Friday"`show will be evaluated only when the form is opened.
vary is used to force a descriptor that is evaluated once by default, or only when it is referenced in certain conditions, to be re-evaluated each time it is referenced. Suppose you have defined a form that allows users to administer machines in a network. One field in the form displays a choices menu from which users can select the machine they want to act on. The field references a directory that contains files corresponding to each machine in the network. You can use the rmenu descriptor to define the choices for the field:
rmenu={ `ls $NetMachines` }Suppose further, though, that machines will be added or removed from the directory list as necessary throughout the life of the form. That means your choices menu will have to change dynamically to reflect the changing contents of the directory. Because rmenu is evaluated only once by default, the code shown above will produce a choices menu that reflects the state of affairs when the form was opened, and not as it has changed since then. To produce a choices menu that changes dynamically, you use vary as follows:
rmenu=vary { `ls $NetMachines` }rmenu will be evaluated whenever it is referenced.