documentation re $-parameters (vs jq)
pkoppstein opened this issue · comments
The discrepancy with jq regarding $-parameters in definitions does not seem to appear in the "Definitions" section:
https://github.com/01mf02/jaq#definitions-1
(Is there any chance that jaq could support $-parameters in definitions? I realize that the jq implementation (as syntactic sugar for "as" declarations) makes them somewhat problematic from a certain point of view, but the discrepancy is very inconvenient.)
I have documented this now in 6c87e65.
Supporting $-arguments in definitions is not so trivial and would make it necessary to treat them in a different way than all other variables, although they look like variables. Therefore, I am reluctant to do this move. Only if there is a significant amount of people asking for it, I might consider it.
@01mf02 - Thank you for your explanation. In case you missed the point, let me emphasize that jq’s implementation strategy was based entirely on ease of implementation, so I would be surprised if it were not also extremely easy for you. The strategy, as I mentioned, is based on simply rewriting defs that include $-parameters by defs without them, followed by suitable as
declarations. This is important not merely because of convenience but because it promotes a clear (declarative) distinction between "regular" and "non-regular" parameters.
(The author of gojq at first tried to implement them “properly”, and then backtracked when it became clear that the difference in semantics was too great.)
The strategy, as I mentioned, is based on simply rewriting defs that include $-parameters by defs without them, followed by suitable
as
declarations.
I'm not sure I understand this correctly ... how would something like def bla(f): f as $x | ($x, $y);
be transformed, if we call jq with --arg x 1 --slurpfile y file2
? (The shadowing of $x
by the output of f
is on purpose`.)
@01mf02 wrote:
how would something like
def bla(f): f as $x | ($x, $y);
be transformed
It wouldn't be transformed at all. The transformation that occurs is from def bla($f):
to def blah(f): f as $f ...
.
Of course this transformation occurs BEFORE global $-variables are considered.
Oh, now I understand what you mean! Ok, this is definitely easier to do than what I thought you were talking about, and it is totally realistic that I get around to implement it soon.
59d4195 adds support for variable arguments in jaq.
Thank you for this excellent and very useful enhancement!