| 4 | 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: |
| 5 | {{{ |
| 6 | include { 'pan/functions' }; |
| 7 | }}} |
| 8 | After this is included, any of the defined functions can be used from within DML blocks. |
| 9 | |
| 10 | == 'self' Utility Functions == |
| 11 | |
| 12 | 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. |
| 13 | |
| 14 | """push(element...) """ |
| 15 | 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 |
| 16 | {{{ |
| 17 | '/mylist' = push('a'); |
| 18 | '/mylist' = push('b'); |
| 19 | }}} |
| 20 | The final value for '/mylist' will be a two-element list containing 'a' and 'b'. |
| 21 | |
| 22 | Be careful, however, because the value of self is not directly modified by the push() function. This means that the following: |
| 23 | {{{ |
| 24 | '/mylist' = { |
| 25 | push('a'); |
| 26 | push('b'); |
| 27 | }; |
| 28 | }}} |
| 29 | will leave '/mylist' with the one-element list 'b'. |
| 30 | |
| 31 | |
| 32 | |
| 33 | == 'object' Utility Functions == |
| 34 | |
| 35 | |