Version 2 (modified by 16 years ago) (diff) | ,
---|
pan/functions Template
TracNav
Several pan programming patterns or idioms occur frequently in machine configurations. The functions defined in the "pan/functions" template provide shortcuts to using those idioms. To access the functions, the template must be included in the machine configuration:
include { 'pan/functions' };
After this is included, any of the defined functions can be used from within DML blocks.
'self' Utility Functions
Often one want to add elements to a resource (list or hash) incrementally with a sequence of assignment statements. Those assignment statements usually being in different templates. The following functions provide simple mechanisms to do so.
"""push(element...) """ This function will return a copy of self with the given value(s) appended to the end. If self is undefined, the function will create a new list with the arguments and return that. An example is
'/mylist' = push('a'); '/mylist' = push('b');
The final value for '/mylist' will be a two-element list containing 'a' and 'b'.
Be careful, however, because the value of self is not directly modified by the push() function. This means that the following:
'/mylist' = { push('a'); push('b'); };
will leave '/mylist' with the one-element list 'b'.