Call a function: Difference between revisions

m (→‎{{header|jq}}: <tt> should be </tt>)
(9 intermediate revisions by 4 users not shown)
Line 840:
<b>Subroutines</b> are provided for compatibility with older, unstructured dialects of BASIC; otherwise they are never really used. They require statements to be numbered, and they can neither receive arguments nor return values: they can only manipulate global variables. The <tt>GOSUB</tt> and <tt>RETURN</tt> statements in fact mirror assembly language 'jump to subroutine' and 'return from subroutine' instructions quite closely.
<syntaxhighlight lang="bbcbasic">200 GOSUB 30050</syntaxhighlight>
 
=={{header|Binary Lambda Calculus}}==
 
Function calling is the sole primitive in the Lambda Calculus. The application of function f on argument a is denoted 01 f a in Binary Lambda Calculus. Multi argument functions are achieved by currying, i.e. a function of the first argument returns a function of the 2nd argument, etc. A good example is the Church numeral 2, which given a function f and an argument x, applies f twice on x: C2 = \f. \x. f (f x). This is written in BLC as
 
<pre>00 00 01 110 01 110 01</pre>
 
=={{header|BQN}}==
 
Line 3,661 ⟶ 3,668:
 
=={{header|langur}}==
There are 3 ways to call a function in langur.
User-defined and built-in functions can be called using parentheses.
 
Built-in functions can also be called using an "unbounded list," which ends at a line return, EOF, closing parenthesis, curly brace, or square bracket, or before a comma preceding a line return.
 
=== parentheses ===
You can always call a function using parentheses.
<syntaxhighlight lang="langur">.x()
#<syntaxhighlight call user-defined functionlang="langur">x()</syntaxhighlight>
 
<syntaxhighlight lang="langur">write(.key, ": ", .valuesomestring)</syntaxhighlight>
# call built-in with parentheses</syntaxhighlight>
 
=== unbounded argument lists ===
In statement context, you can call a function with an unbounded list of arguments.
<syntaxhighlight lang="langur">write .key, ": ", .value
# call built-in with unbounded list</syntaxhighlight>
 
<syntaxhighlight lang="langur">writeln "numbers: ", join ", ", [.a1, .a2a, .a3b, .a4]c</syntaxhighlight>
# unbounded lists on writeln and join
# later function join takes remaining arguments</syntaxhighlight>
 
=== forwarding operator ===
<syntaxhighlight lang="langur">writeln "numbers: ", join(", ", [.a1, .a2, .a3, .a4]), " === "
When passing a single argument, you can use the forwarding operator.
# unbounded list on writeln
# join using parentheses so it doesn't take remaining arguments</syntaxhighlight>
 
<syntaxhighlight lang="langur">vala .sum-> = foldfrom(len
# passes a to the len() function</syntaxhighlight>
f(.sum, .i, .c) .sum + toNumber(.c, 36) x .weight[.i],
0,
pseries len .code,
split ZLS, .code,
)
# split, pseries, and len using unbounded lists, ending before comma preceding line return</syntaxhighlight>
 
<syntaxhighlight lang="langur">for .key in sort(keys .tests) {
...
}
# unbounded list on keys bounded by closing parenthesis of sort</syntaxhighlight>
=={{header|Latitude}}==
 
Line 3,828 ⟶ 3,819:
 
* There is no distinction made in LFE/Erlang between functions that are built-in and those that are not.
* "Built-in" for LFE/Erlang usually can be figured out: if a function has the module name <code>erlang</code>, e.g., <code>(: erlang list_to_integer ... )</codcode>, then it's built-in.
* Most of the functions that come with LFE/Erlang are not even in the <code>erlang</code> module, but exist in other modules (e.g., <code>io</code>, <code>math</code>, etc.) and in OTP.
* One uses user/third-party modules in exactly the same way as one uses built-ins and modules that come with the Erlang distribution.
Line 3,848 ⟶ 3,839:
* Not explicitly.
* However, one can use <code>lambda</code>s to achieve the same effect.
 
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
Line 6,499 ⟶ 6,491:
Here are some examples:
 
<syntaxhighlight lang="ecmascriptwren">var f1 = Fn.new { System.print("Function 'f1' with no arguments called.") }
var f2 = Fn.new { |a, b|
System.print("Function 'f2' with 2 arguments called and passed %(a) & %(b).")
Line 6,543 ⟶ 6,535:
50
</pre>
 
=={{header|XLISP}}==
<syntaxhighlight lang="lisp">; call a function (procedure) with no arguments:
1,006

edits