docs: explain that semicolons separate function arguments (#3685)

The manual's "Defining Functions" section shows only one-argument
functions, so it never says how to pass more than one. This adds a short
paragraph: arguments are separated by `;` in both `def f(a; b):` and
`f(.x; .y)`, and `f(.x, .y)` instead calls a one-argument `f` with the
filter `.x, .y`. It also adds an example for each. `tests/man.test` and
`jq.1.prebuilt` are regenerated.

Fixes #2163
This commit is contained in:
qodelicious authored and GitHub committed 2026-10-22 20:24:55 +02:00
1 parent e440cccc0a
commit 49fbca1242
3 files changed
+49

No files matched your search

Generated
+25
View File
@@ -3522,6 +3522,23 @@ def addvalue($f): \.\.\.;
With either definition, \fBaddvalue(\.foo)\fR will add the current input\'s \fB\.foo\fR field to each element of the array\. Do note that calling \fBaddvalue(\.[])\fR will cause the \fBmap(\. + $f)\fR part to be evaluated once per value in the value of \fB\.\fR at the call site\.
.
.P
Multiple arguments are separated by semicolons, both in the definition and in the call:
.
.IP "" 4
.
.nf
def f(a; b): \.\.\.;
f(\.x; \.y)
.
.fi
.
.IP "" 0
.
.P
A comma does not separate arguments\. \fBf(\.x, \.y)\fR calls a one\-argument \fBf\fR with the single filter \fB\.x, \.y\fR, which outputs \fB\.x\fR and then \fB\.y\fR (see the comma operator above)\.
.
.P
Multiple definitions using the same function name are allowed\. Each re\-definition replaces the previous one for the same number of function arguments, but only for references from functions (or main program) subsequent to the re\-definition\. See also the section below on scoping\.
.
.IP "" 4
@@ -3535,6 +3552,14 @@ jq \'def addvalue(f): \. + [f]; map(addvalue(\.[0]))\'
jq \'def addvalue(f): f as $x | map(\. + $x); addvalue(\.[0])\'
[[1,2],[10,20]]
=> [[1,2,1,2], [10,20,1,2]]
jq \'def f(a; b): [a, b]; f(\.x; \.y)\'
{"x":1,"y":2}
=> [1,2]
jq \'def f(a): [a]; f(\.x, \.y)\'
{"x":1,"y":2}
=> [1,2]
.
.fi
.