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 -
| 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 + |
$ mlr --from data/small --opprint put '
- @sum = 0;
+ sum = 0;
for (k,v in $*) {
if (is_numeric(v)) {
- @sum += $[k];
+ sum += $[k];
}
}
- $sum = @sum
+ $sum = sum
'
a b i x y sum
pan pan 1 0.3467901443380824 0.7268028627434533 2.073593
@@ -2227,18 +2237,15 @@ wye pan 5 0.5732889198020006 0.8636244699032729 6.436913
-$ mlr --opprint --from data/small head -n 2 then put -q '
+$ mlr -n put --jknquoteint -q '
begin {
- @myvar["nesting-is-too-shallow"] = 1;
- @myvar["nesting-is"]["just-right"] = 2;
- @myvar["nesting-is"]["also-just-right"] = 3;
- @myvar["nesting"]["is"]["deeper"] = 4;
- }
- end {
- dump
+ @myvar = {
+ 1: 2,
+ 3: { 4 : 5 },
+ 6: { 7: { 8: 9 } }
+ }
}
+ end { dump }
'
{
"myvar": {
- "nesting-is-too-shallow": 1,
- "nesting-is": {
- "just-right": 2,
- "also-just-right": 3
+ 1: 2,
+ 3: {
+ 4: 5
},
- "nesting": {
- "is": {
- "deeper": 4
+ 6: {
+ 7: {
+ 8: 9
}
}
}
@@ -2290,133 +2295,110 @@ $ mlr --opprint --from data/small head -n 2 then put -q '
-$ mlr --from data/small head -n 2 then put -q '
+$ mlr -n put --jknquoteint -q '
begin {
- @myvar["nesting-is-too-shallow"] = 1;
- @myvar["nesting-is"]["just-right"] = 2;
- @myvar["nesting-is"]["also-just-right"] = 3;
- @myvar["nesting"]["is"]["deeper"] = 4;
+ @myvar = {
+ 1: 2,
+ 3: { 4 : 5 },
+ 6: { 7: { 8: 9 } }
+ }
}
end {
for (k, v in @myvar) {
- @terminal[k] = v
+ print
+ "key=" . k .
+ ",valuetype=" . typeof(v);
}
- emit @terminal, "index1"
}
'
-index1=nesting-is-too-shallow,terminal=1
-index1=nesting-is,just-right=2,also-just-right=3
-index1=nesting,deeper=4
+key=1,valuetype=int
+key=3,valuetype=map
+key=6,valuetype=map
|
-$ mlr --from data/small head -n 2 then put -q '
+$ mlr -n put --jknquoteint -q '
begin {
- @myvar["nesting-is-too-shallow"] = 1;
- @myvar["nesting-is"]["just-right"] = 2;
- @myvar["nesting-is"]["also-just-right"] = 3;
- @myvar["nesting"]["is"]["deeper"] = 4;
- }
- end {
- for ((k1, k2), v in @*) {
- @terminal[k1][k2] = v
+ @myvar = {
+ 1: 2,
+ 3: { 4 : 5 },
+ 6: { 7: { 8: 9 } }
}
- emit @terminal, "basename", "index1"
- }
-'
-basename=myvar,index1=nesting-is-too-shallow,terminal=1
-basename=myvar,index1=nesting-is,just-right=2,also-just-right=3
-basename=myvar,index1=nesting,deeper=4
-
-
-
-
-
-
-$ mlr --from data/small head -n 2 then put -q '
- begin {
- @myvar["nesting-is-too-shallow"] = 1;
- @myvar["nesting-is"]["just-right"] = 2;
- @myvar["nesting-is"]["also-just-right"] = 3;
- @myvar["nesting"]["is"]["deeper"] = 4;
- }
- end {
- for ((k1), v in @myvar["nesting-is"]) {
- @terminal[k1] = v
- }
- emit @terminal, "index1"
- }
-'
-index1=just-right,terminal=2
-index1=also-just-right,terminal=3
-
-
-
+
-$ mlr --from data/small head -n 2 then put -q '
- begin {
- @myvar["nesting-is-too-shallow"] = 1;
- @myvar["nesting-is"]["just-right"] = 2;
- @myvar["nesting-is"]["also-just-right"] = 3;
- @myvar["nesting"]["is"]["deeper"] = 4;
}
end {
for ((k1, k2), v in @myvar) {
- @terminal[k1][k2] = v
+ print
+ "key1=" . k1 .
+ ",key2=" . k2 .
+ ",valuetype=" . typeof(v);
}
- emit @terminal, "index1", "index2"
}
'
-index1=nesting-is,index2=just-right,terminal=2
-index1=nesting-is,index2=also-just-right,terminal=3
-index1=nesting,index2=is,deeper=4
+key1=3,key2=4,valuetype=int
+key1=6,key2=7,valuetype=map
|
-$ mlr --from data/small head -n 2 then put -q '
+$ mlr -n put --jknquoteint -q '
begin {
- @myvar["nesting-is-too-shallow"] = 1;
- @myvar["nesting-is"]["just-right"] = 2;
- @myvar["nesting-is"]["also-just-right"] = 3;
- @myvar["nesting"]["is"]["deeper"] = 4;
+ @myvar = {
+ 1: 2,
+ 3: { 4 : 5 },
+ 6: { 7: { 8: 9 } }
+ }
}
end {
- for ((k1, k2, k3), v in @*) {
- @terminal[k1][k2][k3] = v
+ for ((k1, k2), v in @myvar[6]) {
+ print
+ "key1=" . k1 .
+ ",key2=" . k2 .
+ ",valuetype=" . typeof(v);
}
- emit @terminal, "basename", "index1", "index2"
}
'
-basename=myvar,index1=nesting-is,index2=just-right,terminal=2
-basename=myvar,index1=nesting-is,index2=also-just-right,terminal=3
-basename=myvar,index1=nesting,index2=is,deeper=4
+key1=7,key2=8,valuetype=int
|
+$ mlr --from data/small --opprint put '
+ num suma = 0;
+ for (a = 1; a <= NR; a += 1) {
+ suma += a;
+ }
+ $suma = suma;
+'
+a b i x y suma
+pan pan 1 0.3467901443380824 0.7268028627434533 1
+eks pan 2 0.7586799647899636 0.5221511083334797 3
+wye wye 3 0.20460330576630303 0.33831852551664776 6
+eks wye 4 0.38139939387114097 0.13418874328430463 10
+wye pan 5 0.5732889198020006 0.8636244699032729 15
+
+@@ -2445,13 +2427,22 @@ Notes:In for (start; continuation; update) { body }, the start, continuation, and update statements may be empty, single statements, or -multiple comma-separated statements. If the continuation is empty it defaults +multiple comma-separated statements. If the continuation is empty (e.g. for(i=1;;i+=1)) it defaults to true. In particular, you may use $-variables and/or @-variables in the start, continuation, and/or update steps (as well as the body, of course). + The typedecls such as int or num are optional. If a +typedecl is provided (for a local variable), it binds a variable scoped to the +for-loop regardless of whether a same-name variable is present in outer scope. +If a typedecl is not provided, then the variable is scoped to the for-loop if +no same-name variable is present in outer scope, or if a same-name variable is +present in outer scope then it is modified. + + Miller has no ++ or -- operators. + As with all for/if/while statements in Miller, the curly braces are required even if the body is a single statement, or empty.