First-class functions: Difference between revisions

m (syntax highlighting fixup automation)
Line 1,741:
0.4999999999999999
0.5</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq'''
 
'''Also works with fq, a Go implementation of a large subset of jq'''
 
jq does not support functions as "first class objects" in the sense specified in the task description
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 satisfy the task requirements using idiomatic jq compactly, as follows:
<syntaxhighlight lang=jq>
# Apply g first
def compose(f; g): g | f;
 
def A: [sin, cos, .*.*.];
 
def B: [asin, acos, pow(.; 1/3) ];
 
0.5
| range(0;3) as $i
| compose( A[$i]; B[$i] )
</syntaxhighlight>
{{output}}
Using gojq:
<pre>
0.5
0.5000000000000001
0.5000000000000001
</pre>
 
=={{header|Julia}}==
2,442

edits