[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.6.13 FOR - Emit a template block multiple times

This macro has a slight variation on the standard syntax:

 
FOR <value-name> [ <separator-string> ]

FOR <value-name> (...Scheme expression list)

FOR <value-name> IN "string" [ ... ]

Other than for the last form, the first macro argument must be the name of an AutoGen value. If there is no value associated with the name, the FOR template block is skipped entirely. The scope of the FOR macro extends to the corresponding ENDFOR macro. The last form will create an array of string values named <value-name> that only exists within the context of this FOR loop. With this form, in order to use a separator-string, you must code it into the end of the template block using the (last-for?) predicate function (see section `last-for?' - detect last iteration).

If there are any arguments after the value-name, the initial characters are used to determine the form. If the first character is either a semi-colon (;) or an opening parenthesis ((), then it is presumed to be a Scheme expression containing the FOR macro specific functions for-from, for-by, for-to, and/or for-sep. See section AutoGen Scheme Functions. If it consists of an 'i' an 'n' and separated by white space from more text, then the FOR x IN form is processed. Otherwise, the remaining text is presumed to be a string for inserting between each iteration of the loop. This string will be emitted one time less than the number of iterations of the loop. That is, it is emitted after each loop, excepting for the last iteration.

If the from/by/to functions are invoked, they will specify which copies of the named value are to be processed. If there is no copy of the named value associated with a particular index, the FOR template block will be instantiated anyway. The template must use methods for detecting missing definitions and emitting default text. In this fashion, you can insert entries from a sparse or non-zero based array into a dense, zero based array.

NB: the for-from, for-to, for-by and for-sep functions are disabled outside of the context of the FOR macro. Likewise, the first-for, last-for and for-index functions are disabled outside of the range of a FOR block.

Also: the <value-name> must be a single level name, not a compound name (see section Naming a value).

 
[+FOR var (for-from 0) (for-to <number>) (for-sep ",") +]
... text with various substitutions ...[+
ENDFOR var+]

this will repeat the ... text with various substitutions ... <number>+1 times. Each repetition, except for the last, will have a comma , after it.

 
[+FOR var ",\n" +]
... text with various substitutions ...[+
ENDFOR var +]

This will do the same thing, but only for the index values of var that have actually been defined.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Bruce Korb on September, 30 2006 using texi2html 1.76.

Viewable With Any Browser   autogen Home