Jump to content

Function definition: Difference between revisions

jq
(→‎{{header|TXR}}: Corrections.)
(jq)
Line 882:
 
 
=={{header|jq}}==
Example of a simple function definition:<lang jq>def multiply(a; b): a*b;</lang>
Functions and the composition of functions can also be passed as parameters to other functions. For example, here is a function which expects an array as its input and which takes a function, f, as its argument:<lang jq>def summation(f): reduce .[] as $x (0; . + ($x|f));</lang>If the input consists of JSON objects with attributes "h" and "w", then to compute SIGMA (h * w) we could simply write:<lang jq>summation( .h * .w)</lang>
=={{header|Julia}}==
General function definition
2,511

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.