The following (https://jqplay.org/s/9r9oTh1VFq)
filter:
def addvalue(f): map(. + f); addvalue(.[0])
input:
[[1,2],[10,20]]
gives error:
jq: error (at <stdin>:0): array ([1,2]) and number (1) cannot be added
exit status 5
But the this (https://jqplay.org/s/X7FDfQWubV)
filter:
def addvalue(f): map(. + f); addvalue([1,2])
input:
[[1,2],[10,20]]
output:
[
[
1,
2,
1,
2
],
[
10,
20,
1,
2
]
]
works as expected.
From the jq manual, the following (https://jqplay.org/s/npl2nalQyq) works too:
filter:
def addvalue($f): map(. + $f); addvalue(.[0])
input:
[[1,2],[10,20]]
output:
[
[
1,
2,
1,
2
],
[
10,
20,
1,
2
]
]
In the jq manual it says:
If you want the value-argument behaviour for defining simple functions, you can just use a variable...
Why do I need to use the variable $f in the function definition for addvalue(.[0]) to work?
Thanks!