First-class functions: Difference between revisions

→‎{{header|jq}}: for efficiency, skip A and B
(→‎{{header|jq}}: inefficiency)
(→‎{{header|jq}}: for efficiency, skip A and B)
Line 1,751:
but it does give near-first-class status to functions and functional expressions, which can
for example, be passed as arguments to functions. In fact, it is quite straightforward,
to satisfytranslate the task[[#Wren|Wren]] requirementsentry compactly (but inefficiently) using idiomaticto jq, as follows:
<syntaxhighlight lang=jq>
# Apply g first
Line 1,764:
| compose( A[$i]; B[$i] )
</syntaxhighlight>
ThisHowever this is inefficient because at each iteration (i.e. for each $i), all three components of A and of B are computed.
To avoid this, one would have to write:
<pre>
0.5
| compose(sin; asin), compose(cos; acos), compose(pow(.;3); pow(.; 1/3))
</pre>
{{output}}
Using gojq:
2,442

edits