You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix mlr -s shebang doc and reject arrays/maps in contains/index (#1658) (#2058)
The shebang example `#!/usr/bin/env mlr -s` does not work on Linux
because env(1) does not accept arguments to the interpreter; use
`#!/usr/bin/env -S mlr -s` instead.
`contains` and `index` previously stringified their inputs silently,
so `contains([1,2], $foo)` would match against the literal string
`[1, 2]` and produce surprising results. Both now return a type-error
when either argument is an array or map; help text points users at
`any(arr, func(e){return e == x})` for membership tests.
contains (class=string #args=2) Returns true if the first argument contains the second as a substring. This is like saying `index(arg1, arg2) >= 0`but with less keystroking.
1220
+
contains (class=string #args=2) Returns true if the first argument contains the second as a substring. This is like saying `index(arg1, arg2) >= 0`but with less keystroking. Stringifies non-string scalar inputs; raises an error if either argument is an array or map. To test for array membership, use `any`, e.g. `any([1,2,3], func(e) {return e == $foo})`.
index (class=string #args=2) Returns the index (1-based) of the second argument within the first. Returns -1 if the second argument isn't a substring of the first. Stringifies non-string inputs. Uses UTF-8 encoding to count characters, not bytes.
1262
+
index (class=string #args=2) Returns the index (1-based) of the second argument within the first. Returns -1 if the second argument isn't a substring of the first. Stringifies non-string scalar inputs; raises an error if either argument is an array or map. Uses UTF-8 encoding to count characters, not bytes.
Copy file name to clipboardExpand all lines: docs/src/scripting.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ circle 3 0.3
35
35
Typing this out can get a bit old, if the only thing that changes for you is the filename. Some options include:
36
36
37
37
* On Linux/Mac/etc you can make a script with `#!/bin/sh` which invokes Miller as part of the shell-script body.
38
-
* On Linux/Mac/etc you can make a script with `#!/usr/bin/env mlr -s` which invokes Miller.
38
+
* On Linux/Mac/etc you can make a script with `#!/usr/bin/env -S mlr -s` which invokes Miller.
39
39
* On any platform you can put the reusable part of your command line into a text file (say `myflags.txt`), then `mlr -s myflags-txt filename-which-varies.csv`.
40
40
41
41
Let's look at examples of each.
@@ -135,7 +135,7 @@ Here instead of putting `#!/bin/bash` on the first line, we can put `mlr` direct
Copy file name to clipboardExpand all lines: docs/src/scripting.md.in
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ GENMD-EOF
13
13
Typing this out can get a bit old, if the only thing that changes for you is the filename. Some options include:
14
14
15
15
* On Linux/Mac/etc you can make a script with `#!/bin/sh` which invokes Miller as part of the shell-script body.
16
-
* On Linux/Mac/etc you can make a script with `#!/usr/bin/env mlr -s` which invokes Miller.
16
+
* On Linux/Mac/etc you can make a script with `#!/usr/bin/env -S mlr -s` which invokes Miller.
17
17
* On any platform you can put the reusable part of your command line into a text file (say `myflags.txt`), then `mlr -s myflags-txt filename-which-varies.csv`.
Copy file name to clipboardExpand all lines: pkg/dsl/cst/builtin_function_manager.go
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -581,25 +581,27 @@ Arrays are new in Miller 6; the substr function is older.`,
581
581
{
582
582
name: "index",
583
583
class: FUNC_CLASS_STRING,
584
-
help: `Returns the index (1-based) of the second argument within the first. Returns -1 if the second argument isn't a substring of the first. Stringifies non-string inputs. Uses UTF-8 encoding to count characters, not bytes.`,
584
+
help: `Returns the index (1-based) of the second argument within the first. Returns -1 if the second argument isn't a substring of the first. Stringifies non-string scalar inputs; raises an error if either argument is an array or map. Uses UTF-8 encoding to count characters, not bytes.`,
585
585
binaryFunc: bifs.BIF_index,
586
586
examples: []string{
587
587
`index("abcde", "e") gives 5`,
588
588
`index("abcde", "x") gives -1`,
589
589
`index(12345, 34) gives 3`,
590
590
`index("forêt", "t") gives 5`,
591
+
`index([1,2,3], 2) gives (error)`,
591
592
},
592
593
},
593
594
{
594
595
name: "contains",
595
596
class: FUNC_CLASS_STRING,
596
-
help: `Returns true if the first argument contains the second as a substring. This is like saying `+"`index(arg1, arg2) >= 0`"+`but with less keystroking.`,
597
+
help: `Returns true if the first argument contains the second as a substring. This is like saying `+"`index(arg1, arg2) >= 0`"+`but with less keystroking. Stringifies non-string scalar inputs; raises an error if either argument is an array or map. To test for array membership, use `+"`any`"+`, e.g. `+"`any([1,2,3], func(e) {return e == $foo})`"+`.`,
0 commit comments