Jump to content

Function prototype: Difference between revisions

m (syntax highlighting fixup automation)
Line 943:
l.length; // 2
</syntaxhighlight>
 
=={{header|jq}}==
jq does not have "function prototypes" in the strict sense, so this entry focuses on jq function signatures
as specified in function definitions.
 
jq does not limit the number of formal parameters of a function and supports multi-arity functions, but each allowed
"restriction" to a particular arity must be specified explicitly.
 
Although jq does not support varargs functions, their effect can be
achieved by using an array-valued argument in conjunction with
"destructuring", as illustrated below.
 
Note also that:
* any restrictions on the allowed values of the parameters must be specified programmatically and are only checked at run-time;
* function definitions may be included within function definitions;
* recursive functions are allowed, but calls to a function can only occur within the scope of its definition.
* a function of a particular arity can be defined more than once, with lexical scoping rules determining how each invocation will be handled.
 
In the following examples, only `def` and `as` are jq keywords, and .... is used to indicate ellipsis.
 
<syntaxhighlight lang=jq>
def Func: # no arguments
 
def Func(a;b): # two arguments
 
def Vararg(v):
v as [$a1, $a2] .... # if v is an array, then $a1 will be the first item specified by v, or else null, and so on
 
def Vararg(a; v):
v as [$a1, $a2] .... # if v is an array, then $a1 will be the first item specified by v, or else null, and so on
<syntaxhighlight lang=jq>
 
 
=={{header|Julia}}==
2,469

edits

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