diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2013-10-06 20:39:10 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2013-10-06 20:39:10 -0700 |
commit | 7c8c8d326bbb8b9725efa6a3c364d3426a7cdca9 (patch) | |
tree | 86984ce58ca520cd3402fb9b77732d24f8046735 /txr.1 | |
parent | 7a7b1d26622b2f7df03b60847f622111296b008d (diff) | |
download | txr-7c8c8d326bbb8b9725efa6a3c364d3426a7cdca9.tar.gz txr-7c8c8d326bbb8b9725efa6a3c364d3426a7cdca9.tar.bz2 txr-7c8c8d326bbb8b9725efa6a3c364d3426a7cdca9.zip |
New feature: :vars argument in repeat and rep directives in an output
block, for specifying variables to include in iteration whose
presence repeat is not able to deduce.
* match.c (extract_bindings): New argument, vars, specifies
additional variables to consider.
(do_output_line, do_output): Process :vars argument of repeat
and rep directive.
* txr.1: Updated.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 48 |
1 files changed, 43 insertions, 5 deletions
@@ -3789,13 +3789,49 @@ are none, or none of them activate, then @(last) is considered. If none of those clauses are present or apply, then the repetition is processed using the main clause. -Repeat supports an optional keyword argument: +Repeat supports arguments. - @(repeat [:counter <symbol>]) + @(repeat [:counter <symbol>] [:vars (<symbol>*)]) -This designates a symbol which will behave as an integer variable over the -scope of the clauses inside the repeat. The variable provides access to the -reptition count, starting at zero, incrementing with each repetition. +The :counter argumnt designates a symbol which will behave as an integer +variable over the scope of the clauses inside the repeat. The variable provides +access to the reptition count, starting at zero, incrementing with each +repetition. + +The :vars argument specifies a list of variables. The repeat directive +will pick out from this list those variables which have bindings. +It will assume that all these variables occur in the repeat block and +are to be iterated. This syntax is needed for situations in which @(repeat) +is not able to deduce the existence of a variable in the block. +It does not dig very deeply to discover variables, and does not "see" +variables that are referenced via embedded TXR Lisp expressions. +For instance, the following produces no output: + + @(bind list ("a" "b" "c")) + @(output) + @(repeat) + @(format nil "<~a>" list) + @(end) + @(end) + +Although the list variable appears in the repeat block, it is embedded +in a TXR Lisp construct. That construct will never be evaluated because +no repetitions take place: the repeat construct doesn't find any variables +and so doesn't iterate. The remedy is to provide a little help via +the :vars parameter: + + @(bind list ("a" "b" "c")) + @(output) + @(repeat :vars (list)) + @(format nil "<~a>" list) + @(end) + @(end) + +Now the repeat block iterates over list and the output is: + + <a> + <b> + <c> .SS Nested Repeats @@ -3823,6 +3859,8 @@ but everything is specified within one line: More than one @(rep) can occur within a line, mixed with other material. A @(rep) can be nested within a @(repeat) or within another @(rep). +Also, @(rep) accepts the same :counter and :vars arguments. + .SS Repeat and Rep Examples Example 1: show the list L in parentheses, with spaces between |