From ca0a162bd3bd2c0c9d575cd9e6e7a3ba57ec7e01 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Fri, 24 Feb 2017 17:51:08 -0800 Subject: [PATCH] for-loop doc iterate --- doc/content-for-reference-dsl.html | 64 +++-- doc/data/for-oosvar-example-0b.sh | 15 +- doc/data/for-oosvar-example-0c.sh | 16 +- doc/data/for-oosvar-example-0d.sh | 19 +- doc/data/for-oosvar-example-0e.sh | 19 +- doc/data/for-oosvar-example-0f.sh | 14 -- doc/data/for-oosvar-example-0g.sh | 14 -- doc/data/for-srec-example-3.sh | 6 +- doc/data/triple-for-example-1.sh | 7 + ...for-example.sh => triple-for-example-2.sh} | 0 doc/reference-dsl.html | 225 +++++++++--------- 11 files changed, 195 insertions(+), 204 deletions(-) delete mode 100644 doc/data/for-oosvar-example-0f.sh delete mode 100644 doc/data/for-oosvar-example-0g.sh create mode 100644 doc/data/triple-for-example-1.sh rename doc/data/{triple-for-example.sh => triple-for-example-2.sh} (100%) diff --git a/doc/content-for-reference-dsl.html b/doc/content-for-reference-dsl.html index b71621768..0bf66fc9b 100644 --- a/doc/content-for-reference-dsl.html +++ b/doc/content-for-reference-dsl.html @@ -744,7 +744,18 @@ as the expression is parsed, before any input records are ingested. POKI_INCLUDE_AND_RUN_ESCAPED(data/single-for-example-1.sh)HERE POKI_INCLUDE_AND_RUN_ESCAPED(data/single-for-example-2.sh)HERE -

For-loop over the current stream record

+

Note that the value corresponding to a given key may be gotten as through a +computed field name using square brackets as in $[key] for +stream records, or by indexing the looped-over variable using square brackets. + +

Key-value for-loops

+ +

Single-level keys may be gotten at using either for(k,v) or +for((k),v); multi-level keys may be gotten at using +for((k1,k2,k3),v) and so on. The v variable will be bound to +to a scalar value (a string or a number) if the map stops at that level, or to +a map-valued variable if the map goes deeper. If the map isn’t deep +enough then the loop body won’t be executed. POKI_RUN_COMMAND{{cat data/for-srec-example.tbl}}HERE POKI_INCLUDE_AND_RUN_ESCAPED(data/for-srec-example-1.sh)HERE @@ -762,23 +773,20 @@ itself: POKI_INCLUDE_AND_RUN_ESCAPED(data/for-srec-example-2.sh)HERE It can be confusing to modify the stream record while iterating over a copy of it, so -instead you might find it simpler to use an out-of-stream variable in the loop and only update +instead you might find it simpler to use a local variable in the loop and only update the stream record after the loop: POKI_INCLUDE_AND_RUN_ESCAPED(data/for-srec-example-3.sh)HERE -

For-loop over out-of-stream variable

- -

This is similar to looping over the current stream record except for -additional degrees of freedom: you can start iterating on sub-hashmaps of an -out-of-stream variable; you can loop over nested keys; you can loop over all -out-of-stream variables. As with for-loops over stream records, the bound -variables are bound to a copy of the sub-hashmap as it was before the loop -started. The sub-hashmap is specified by square-bracketed indices after -in, and additional deeper indices are bound to loop key-variables. The -terminal values are bound to the loop value-variable whenever the keys are not -too shallow. The value-variable may refer to a terminal (string, number) or it -may be map-valued if the map goes deeper. Example indexing is as follows: +

You can also start iterating on sub-hashmaps of an out-of-stream or local +variable; you can loop over nested keys; you can loop over all out-of-stream +variables. The bound variables are bound to a copy of the sub-hashmap as it +was before the loop started. The sub-hashmap is specified by square-bracketed +indices after in, and additional deeper indices are bound to loop +key-variables. The terminal values are bound to the loop value-variable +whenever the keys are not too shallow. The value-variable may refer to a +terminal (string, number) or it may be map-valued if the map goes deeper. +Example indexing is as follows: POKI_INCLUDE_ESCAPED(data/for-oosvar-example-0a.txt)HERE @@ -787,38 +795,44 @@ Suppose the out-of-stream variable @myvar is populated as follows: POKI_INCLUDE_AND_RUN_ESCAPED(data/for-oosvar-example-0b.sh)HERE -

Then the too-shallow parts — indexed by the basename myvar -and the index "nesting-is-too-shallow" — have depth two -(basename and one index specify a terminal value) and can be gotten as follows: +

Then we can get at various values as follows: +
POKI_INCLUDE_AND_RUN_ESCAPED(data/for-oosvar-example-0c.sh)HERE + POKI_INCLUDE_AND_RUN_ESCAPED(data/for-oosvar-example-0d.sh)HERE - -

The "just-right" parts have depth three (basename and two indices -specify a terminal value) and can be gotten at by any of the following: - +

POKI_INCLUDE_AND_RUN_ESCAPED(data/for-oosvar-example-0e.sh)HERE -POKI_INCLUDE_AND_RUN_ESCAPED(data/for-oosvar-example-0f.sh)HERE -POKI_INCLUDE_AND_RUN_ESCAPED(data/for-oosvar-example-0g.sh)HERE +

C-style triple-for loops

These are supported as follows: -POKI_INCLUDE_AND_RUN_ESCAPED(data/triple-for-example.sh)HERE +POKI_INCLUDE_AND_RUN_ESCAPED(data/triple-for-example-1.sh)HERE +POKI_INCLUDE_AND_RUN_ESCAPED(data/triple-for-example-2.sh)HERE Notes: