Call a function: Difference between revisions

m (→‎{{header|FutureBasic}}: Minor edits to descriptions)
(24 intermediate revisions by 13 users not shown)
Line 668:
<syntaxhighlight lang="axe">USER()
axeFunc()</syntaxhighlight>
=={{header|BASIC256BASIC}}==
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic256">function Copialo$ (txt$, siNo, final$)
Line 707 ⟶ 708:
Igual que la entrada de FreeBASIC.
</pre>
 
=={{header|Batch File}}==
 
Line 838 ⟶ 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 1,805 ⟶ 1,814:
# a function's arity is a property of its behavior and not
# of its definition</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight>
func sqr n .
return n * n
.
print sqr 3
#
proc divmod a b . q r .
q = a div b
r = a mod b
.
divmod 11 3 q r
print q & " " & r
#
subr sqr2
a = a * a
.
a = 5
sqr2
print a
</syntaxhighlight>
 
=={{header|Ecstasy}}==
Line 1,821 ⟶ 1,852:
<b><i>Calling a function with optional arguments:</i></b>
<syntaxhighlight lang="java">
module CallOptArgsFunc {
static Int foo(Int a=0, Int b=99, Int c=-1) {
{
static Int foo(Int a=0, Int b=99, Int c=-1)
{
return a + b + c;
}
 
void run() {
{
@Inject Console console;
console.printlnprint($"{foo() == {foo()}");
console.printlnprint($"{foo(1) == {foo(1)}");
console.printlnprint($"{foo(1, 2) == {foo(1, 2)}");
console.printlnprint($"{foo(1, 2, 3) == {foo(1, 2, 3)}");
}
}
}
</syntaxhighlight>
 
Output:
{{out}}
<syntaxhighlight>
<pre>
foo() == 98
foo(1) == 9998
foo(1, 2) == 299
foo(1, 2, 3) == 62
foo(1, 2, 3)=6
</syntaxhighlight>
</pre>
 
<b><i>Calling a function with a variable number of arguments:</i></b>
<syntaxhighlight lang="java">
module CallVarArgsFunc {
{
// Ecstasy does not have a var-args concept; instead, array notation is used
static Int foo(Int[] args = []) {
{
return args.size;
}
 
void run() {
{
@Inject Console console;
console.printlnprint($"{foo() == {foo()}");
console.printlnprint($"{foo([]) == {foo([])}");
console.printlnprint($"{foo([1]) == {foo([1])}");
console.printlnprint($"{foo([1, 2]) == {foo([1, 2])}");
console.printlnprint($"{foo([1, 2, 3]) == {foo([1, 2, 3])}");
}
}
}
</syntaxhighlight>
Output:
<syntaxhighlight>
foo() == 0
foo([]) == 0
foo([1]) == 1
foo([1, 2]) == 2
foo([1, 2, 3]) == 3
</syntaxhighlight>
 
{{out}}
<pre>
foo()=0
foo([])=0
foo([1])=1
foo([1, 2])=2
foo([1, 2, 3])=3
</pre>
 
<b><i>Calling a function with named arguments:</i></b>
<syntaxhighlight lang="java">
module CallNamedArgsFunc {
static String foo(Int a=1, Int b=2, Int c=3) {
{
static String foo(Int a=1, Int b=2, Int c=3)
{
return $"a:{a}, b:{b}, c:{c}";
}
 
void run() {
{
@Inject Console console;
console.printlnprint($"{foo(c=9, b=8, a=7) == {foo(c=9, b=8, a=7)}");
console.printlnprint($"{foo(4, c=6, b=5) == {foo(4, c=6, b=5)}");
console.printlnprint($"{foo(c=99) == {foo(c=99)}");
}
}
}
</syntaxhighlight>
Output:
<syntaxhighlight>
foo(c=9, b=8, a=7) == a:7, b:8, c:9
foo(4, c=6, b=5) == a:4, b:5, c:6
foo(c=99) == a:1, b:2, c:99
</syntaxhighlight>
 
{{out}}
<pre>
foo(c=9, b=8, a=7)=a:7, b:8, c:9
foo(4, c=6, b=5)=a:4, b:5, c:6
foo(c=99)=a:1, b:2, c:99
</pre>
 
<b><i>Using a function in first-class context within an expression:</i></b> Functions are always first class in Ecstasy; everything (including classes, types, methods, properties, functions, variables, etc.) is an object.
<syntaxhighlight lang="java">
module FirstClassFunctions {
{
@Inject Console console;
void run() {
{
function Int(String) stringLen = s -> s.size;
function Int(Int, Int) sum = (n1, n2) -> n1+n2;
String[] testData = ["abc", "easy", "as", "123"];
console.printlnprint($|total string length of values in {testData} =\
| {testData.map(stringLen).reduce(0, sum)}
);
}
}
}
</syntaxhighlight>
 
Output:
{{out}}
<syntaxhighlight>
<pre>
total string length of values in [abc, easy, as, 123] = 12
</pre>
</syntaxhighlight>
 
<b><i>Obtaining the return value of a function:</i></b>
<syntaxhighlight lang="java">
module ObtainReturnValues {
(Int, String, Dec) foo() {
{
(Int, String, Dec) foo()
{
return 3, "hello!", 9.87;
}
 
void run() {
{
foo(); // ignore return values
Int i1 = foo(); // only use first returned value
Line 1,940 ⟶ 1,961:
 
@Inject Console console;
console.printlnprint($"{i3={i3}, {s3={s3}, {d3={d3}, {t={t}");
}
}
}
</syntaxhighlight>
 
Output:
{{out}}
<syntaxhighlight>
<pre>
i3=3, s3=hello!, d3=9.87, t=(3, hello!, 9.87)
</pre>
</syntaxhighlight>
 
<b><i>Distinguishing built-in functions and user-defined functions:</i></b>
Line 1,953 ⟶ 1,975:
// Ecstasy does not have any built-in functions. However, there are two keywords
// ("is" and "as") that use a function-like syntax:
module IsAndAs {
Int|String foo() {
Int|String foo()
{
return "hello";
}
 
void run() {
{
@Inject Console console;
Object o = foo();
if (o.is(String)) { // <- looks like a function call
{
String s = o.as(String); // <- looks like a function call
console.printlnprint($"foo returned the string: {s.quoted()}");
}
}
}
}
</syntaxhighlight>
 
Output:
{{out}}
<syntaxhighlight>
<pre>
foo returned the string: "hello"
</pre>
</syntaxhighlight>
 
<b><i>Distinguishing subroutines and functions:</i></b> There is no such thing as a subroutine in Ecstasy. There are only methods (virtual functions with a "this"), functions, and object constructors.
Line 1,983 ⟶ 2,002:
<b><i>Is partial application possible and how:</i></b>
<syntaxhighlight lang="java">
module PartialApplication {
void foo(String s, Int i, Dec d) {
{
void foo(String s, Int i, Dec d)
{
@Inject Console console;
console.printlnprint($"inside call to foo({s=}, {i=}, {d=})");
}
 
void run() {
{
// note that the "&" obtains the reference to the function, and suppresses the
// invocation thereof, so it is *allowed* in all three of these cases, but it
Line 2,003 ⟶ 2,019:
partBound("hello", 2.718);
allBound();
}
}
}
</syntaxhighlight>
Output:
<syntaxhighlight>
inside call to foo(nothing, 0, 0)
inside call to foo(hello, 99, 2.718)
inside call to foo(world, 99, 3.14)
</syntaxhighlight>
 
{{out}}
<pre>
inside call to foo(s=nothing, i=0, d=0)
inside call to foo(s=hello, i=99, d=2.718)
inside call to foo(s=world, i=99, d=3.14)
</pre>
 
=={{header|Elena}}==
Line 2,095 ⟶ 2,112:
end
</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
fun task = void by text about, fun code
writeLine(0U00b7 + " " + about)
code()
end
fun answer = void by var message do writeLine(" " + message) end
# few definitions
fun noArgumentsFunction = int by block do return 97 end
fun fixedArgumentsFunction = void by var a, var b do end
fun variadicFunction = void by text a, some var values do end
fun funArgumentFunction = var by fun f, var b do return f() + b end
task("Calling a function that requires no arguments", void by block
answer("Is supported.")
noArgumentsFunction()
end)
task("Calling a function with a fixed number of arguments", void by block
answer("Is supported.")
fixedArgumentsFunction(97, 3.14)
end)
task("Calling a function with optional arguments", void by block
answer("Not supported in EMal.")
end)
task("Calling a function with a variable number of arguments", void by block
answer("Variadic functions are supported.")
variadicFunction("mandatory", 97, 3.14)
variadicFunction("mandatory", 97)
end)
task("Calling a function with named arguments", void by block
answer("Not supported in EMal.")
end)
task("Using a function in statement context", void by block
answer("Is supported.")
if true do noArgumentsFunction()
else do fixedArgumentsFunction(97, 3.14) end
end)
task("Using a function in first-class context within an expression", void by block
answer("Functions are first class, can be passed as arguments and returned.")
answer(funArgumentFunction(noArgumentsFunction, 3.14))
end)
task("Obtaining the return value of a function", void by block
answer("Is supported.")
int value = noArgumentsFunction()
answer(value)
end)
task("Distinguishing built-in functions and user-defined functions", void by block
answer("No distinction.")
end)
task("Distinguishing subroutines and functions", void by block
answer("No distinction, we support void return type.")
end)
task("Stating whether arguments are passed by value or by reference", void by block
answer("Pass by value, but text, blob, objects hold a reference.")
end)
task("Is partial application possible and how", void by block
answer("Is supported.")
^|I had some confusion about partial application and currying, thanks to these links:
| https://stackoverflow.com/questions/218025/what-is-the-difference-between-currying-and-partial-application
| https://web.archive.org/web/20161023205431/http://www.uncarved.com/articles/not_curryin
|^
# Partial applying
fun add = int by int a, int b do return a + b end
fun partial = fun by fun f, int a
return int by int b
return add(a, b)
end
end
fun add7 = partial(add, 7)
answer(add(7, 5))
answer(add7(5))
# Currying
fun addN = fun by int n
return int by int x
return x + n
end
end
fun plus = int by int a, int b
fun addA = addN(a)
return addA(b)
end
answer(plus(7, 5))
end)
</syntaxhighlight>
{{out}}
<pre>
· Calling a function that requires no arguments
Is supported.
· Calling a function with a fixed number of arguments
Is supported.
· Calling a function with optional arguments
Not supported in EMal.
· Calling a function with a variable number of arguments
Variadic functions are supported.
· Calling a function with named arguments
Not supported in EMal.
· Using a function in statement context
Is supported.
· Using a function in first-class context within an expression
Functions are first class, can be passed as arguments and returned.
100.14
· Obtaining the return value of a function
Is supported.
97
· Distinguishing built-in functions and user-defined functions
No distinction.
· Distinguishing subroutines and functions
No distinction, we support void return type.
· Stating whether arguments are passed by value or by reference
Pass by value, but text, blob, objects hold a reference.
· Is partial application possible and how
Is supported.
12
12
12
</pre>
 
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">
Line 2,927 ⟶ 3,061:
There are no ''differences between calling subroutines and functions'' because J defines neither <code>subroutines</code> nor <code>functions</code>. Instead, J defines <code>verbs</code>, <code>adverbs</code>, and <code>conjunctions</code> which for the purpose of this task are treated as functions. (All of the above examples used verbs. J's adverbs and conjunctions have stronger [[wp:Valence|valence]] than its verbs.)
=={{header|Java}}==
<kbd><i>"Calling a function that requires no arguments."</i></kbd><br/>
The parentheses are required.
<syntaxhighlight lang="java">
Object.methodName();
</syntaxhighlight>
<p>
<kbd><i>"Calling a function with a fixed number of arguments."</i></kbd>
<syntaxhighlight lang="java">
Object.methodName("rosetta", "code");
</syntaxhighlight>
</p>
<p>
<kbd><i>"Calling a function with optional arguments."</i></kbd><br/>
Java doesn't offer the ability to optionalize parameters, although there is something similar.<br/>
A <kbd>varargs</kbd>, or "Variable Arguments", parameter, could be of 0 length.<br/>
So if you're only parameter is a <kbd>vararg</kbd> parameter, it's possible to not supply any input.
This could be viewed, in some situations, as an optional parameter.
</p>
<p>
<kbd><i>"Calling a function with a variable amount of arguments."</i></kbd><br/>
There is no special syntax, you simply offer the arguments as required.
</p>
<p>
<kbd><i>"Calling a function with named arguments."</i></kbd><br/>
Java does not offer this feature.
</p>
<p>
<kbd><i>"Using a function in a statement context."</i></kbd><br/>
Java is not a functional programming language, although Java 8 added basic closures and lambda expressions.<br/>
They are not in anyway as robust as functional languages like JavaScript.<br/>
A lambda works specifically with an <code>interface</code> that requires only 1 abstraction.<br/>
Consider the following <kbd>interface</kbd>.
<syntaxhighlight lang="java">
interface Example {
int add(int valueA, int valueB);
}
</syntaxhighlight>
You could then implement this interface with a lambda, as opposed to creating an anonymous-class.<br/>
Consider the following method.
<syntaxhighlight lang="java">
int sum(Example example) {
return example.add(1, 2);
}
</syntaxhighlight>
You would then provide the closure, or the functionality of the abstraction, during assignment.
<syntaxhighlight lang="java">
Example example = (valueA, valueB) -> valueA + valueB;
sum(example);
</syntaxhighlight>
</p>
<p>
<kbd><i>"Using a function in first-class context with an expression."</i></kbd><br />
First-class context is out-of-scope for Java, which is statically-typed.
</p>
<p>
<kbd><i>"Obtaining the return value of a function."</i></kbd><br />
</p>
<syntaxhighlight lang="java">
String string = Object.methodName("rosetta", "code");
</syntaxhighlight>
<p>
<kbd><i>"Distinguishing built-in functions and user-defined functions."</i></kbd><br />
There is no ambiguity between built-in functions and user-defined functions.
</p>
<p>
<kbd><i>"Distinguishing subroutines and functions."</i></kbd><br />
Java refers to all procedures as methods.<br/>
As with other languages, such as Visual Basic, which uses <kbd>Sub</kbd>, and <kbd>Function</kbd>,
there is no ambiguity from methods which return values and those that don't.
</p>
<p>
The defining factor is within the method definition.<br/>
A return-type is declared before the method name, and <code>void</code> is used when there is no returned value.
<syntaxhighlight lang="java">
String methodA();
void methodB();
</syntaxhighlight>
</p>
<p>
<kbd><i>"Stating whether arguments are passed by value or by reference."</i></kbd><br />
The concept of pass-by-value and pass-by-reference is somewhat a redefined measure within Java.<br/>
For the most part, everything is pass-by-value; there are no pointers and dereferencing, as with C, C++, and Rust.<br/>
Although, if you're passing an object, it can be viewed as pass-by-reference, since the operation is occurring on the actual object,
and a new value is not created.<br/>
Java is essentially an language that was influenced by languages which use pass-by-reference, so it's abstraction is lacking.
</p>
<p>
<kbd><i>"Is partial application possible and how."</i></kbd><br />
Not without a closure.<br/>
I found the following example on [https://en.wikipedia.org/wiki/Partial_application#Implementations Wikipedia - Partial application].
</p>
<syntaxhighlight lang="java">
<X, Y, Z> Function<Y, Z> exampleA(BiFunction<X, Y, Z> exampleB, X value) {
return y -> exampleB.apply(value, y);
}
</syntaxhighlight>
 
 
 
<br />
 
Here is an alternate demonstration.<br />
Java does not have functions, but Java classes have "methods" which are equivalent.
 
Line 2,999 ⟶ 3,235:
* Is partial application possible and how
Don't know
 
=={{header|JavaScript}}==
 
Line 3,072 ⟶ 3,309:
'''Using a function in statement context'''
 
The assignment to a local variable (e.g. <tt>(2*2) as $two</tt>) is similar to a statement context in that the expression as a whole does nothing to the flow of values from its input to its output.
 
'''Using a function in first-class context within an expression'''
Line 3,098 ⟶ 3,335:
 
See [[Currying#jq]].
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">
Line 3,193 ⟶ 3,431:
=={{header|Kotlin}}==
In Kotlin parameters are always passed by value though, apart from the (unboxed) primitive types, the value passed is actually a reference to an object.
<syntaxhighlight lang="scalakotlin">//fun versionfun1() 1.0.6= println("No arguments")
 
fun fun1() = println("No arguments")
 
fun fun2(i: Int) = println("One argument = $i")
Line 3,211 ⟶ 3,447:
fun fun8(x: String) = { y: String -> x + " " + y }
 
fun main(args: Array<String>) {
fun1() // no arguments
fun2(2) // fixed number of arguments, one here
Line 3,221 ⟶ 3,457:
println(1 + fun6(4, ::fun5) + 3) // first class context within an expression
println(fun5(5)) // obtaining return value
println(Mathkotlin.math.round(2.5)) // no distinction between built-in and user-defined functions, though former usually have a receiver
fun1() // calling sub-routine which has a Unit return type by default
println(fun7(11)) // calling function with a return type of Double (here explicit but can be implicit)
Line 3,237 ⟶ 3,473:
20
25
2.0
3
No arguments
5.5
Hello world
</pre>
 
=={{header|Lambdatalk}}==
In lambdatalk functions are abstractions {lambda {args} body} whose behaviour is best explained as a part of such a complete expression {{lambda {args} body} values}.
Line 3,294 ⟶ 3,531:
More can be seen in http://lambdaway.free.fr/lambdawalks/?view=lambda
</syntaxhighlight>
=={{header|Lang}}==
<syntaxhighlight lang="lang">
fp.noArgs = () -> \!
fp.noArgs()
 
# For user defined-functions, the argument count is not checked: If too many arguments were provided, they are ignored. If not enough arguments were provided, the last argument will be duplicated (If none was provided, VOID values will be filled in). [This process is is referred to as implict argument duplication]
fp.noArgs(42) # No Error nor Warning
 
fp.fixArgs = ($x, $y) -> \!
fp.fixArgs(1, 2)
 
fp.fixArgs(2) # Fix args will be called with $x=2 and $y=2
fp.fixArgs() # Fix args will be called with $x=VOID and $y=VOID
 
# fn.argCntX (X must be replaced with 0, 1, 2, 3, 4, or 5) can be used to force the caller to provided the exact argument count
# fn.argCntX must be called with the function to apply the constraint to and will return a new function
fp.realFixArgs = fn.argCnt2(fp.fixArgs)
fp.realFixArgs(1, 2)
 
fp.realFixArgs() # Error
fp.realFixArgs(1) # Error
fp.realFixArgs(1, 2, 3) # Error
 
# Arrays can be unpacked in function calls
&values $= [1, 2]
fp.fixArgs(&values...) # Fix args will be called with $x=1 and $y=2
 
 
# In Lang there are text and array varags parameters
fp.varArgsText = ($text...) -> \!
fp.varArgsText(1) # Var args text will be called with "1"
fp.varArgsText(1, 2) # Var args text will be called with "1, 2"
fp.varArgsText(1,2) # Var args text will be called with "1,2"
fp.varArgsText(1,text ,3) # Var args text will be called with "1,text ,3"
 
fp.varArgsArray = (&args...) -> \!
fp.varArgsArray(1) # Var args array will be called with [1]
fp.varArgsArray(1, 2) # Var args array will be called with [1, 2]
fp.varArgsArray(1,2) # Var args array will be called with [1, 2]
fp.varArgsArray(1,text ,3) # Var args array will be called with [1, text, 3]
 
# Functions with named arguments can not be created
 
# Using a function in a statement context
$x = fp.fixArgs(1, 2)
 
# Functions (Even predefined and linker functions) can be used as values
fp.retAFunc = () -> {
return ($x) -> \!
}
fp.func = fp.retAFunc()
fp.func(2)
 
# Multiple call-expressions can be used directly
fp.retAFunc()(2)
 
fp.retAFunc = () -> return fn.println
fp.retAFunc()(test, values)
 
fp.retAFunc = () -> return ln.loadModule
fp.retAFunc()(x.lm) # Error, because file not found
 
# The return value or the thrown error can be obtained with the assignment operator
fp.inc2 = ($x) -> return parser.op($x + 2)
$ret = fp.inc2(40) # $ret is 42
 
# Built-in (They are called predefined functions in Lang) start with the "func." or "fn." prefix wheras user-defined functions start with "fp."
# Linker functions start with "linker." or "ln."
# Predefined and linker functions can be stored in a user-defined function
fp.userDefinedFunc = fn.println
fp.userDefinedFunc(Called println)
 
# In Lang there are no subroutines
 
# In Lang functions can have call-by-pointer values
# $ptr is a pointer to the called value
fp.callByPtr = ($[ptr]) -> \!
fp.callByPtr(42) # This will create a pointer to an anonymous value, therefor it can not be changed
 
fp.inc2 = ($[ptr]) -> $*ptr += 2
fp.inc2(40) # Error
$val = 40
fp.inc2($val) # $val is now 42
 
# Functions can also be called with pointers directly
fp.inc2 = ($ptr) -> $*ptr += 2
fp.inc2(40) # Multiple Errors (Value will be dereferenced as NULL -> + is not defined for NULL and INT AND anonymous values can not be changed)
 
$val = 40
fp.inc2($[val]) # $val is now 42
 
# Partial apllication of functions is possible by using combinator functions
# The simplest combinator function-family is the A combinator family (Other families change the order of arguments, can call multiple function, ...)
fp.partialAdd = fn.combA2(fn.add) # When all arguments for fn.combA2(a, b, c) are provided, the execution of a(b, c) will begin
fp.add42 = fp.partialAdd(42) # Creates a function which still needs 1 argument
fp.add42(2) # Will return 44
 
# Without the use of fn.argCntX 0 args can also be provied
fp.add42()()()(2) # Will also return 44
</syntaxhighlight>
 
===Special function-related features===
<syntaxhighlight lang="lang">
# The function argument auto un-pack operator (▲ or +|) can be used to create a function which must be called with an array value that is automatically unpacked
fp.fixArgs = ($x, $y) -> \!
fp.unpackingFixArgs $= +|fp.fixArgs
fp.unpackingFixArgs(&values) # Fix args will be called with $x=1 and $y=2
 
# The function argument auto pack operator (▼ or -|) can be used to cerate a function wich must be called with varargs and will call the original function with a single array argument
fp.arrayArg = (&arr) -> \!
fp.packingArrayArg $= -|fp.arrayArg
fp.packingArrayArg(1, 2) # Array arg will be called with [1, 2]
 
# Functions can also be called with the pipe operators (|, >>, and >>>)
# The "|" and ">>" pipe operators are identical apart from the operator precedence
# The ">>>" pipe operator automatically unpacks array values
fp.func = ($x) -> \!
parser.op(42 | fp.func) # fp.func is called with 42
parser.op(42 >> fp.func) # fp.func is called with 42
parser.op([42] >>> fp.func) # fp.func is called with 42
 
# Function calls can be concatinated with the concat operator (|||)
fp.incAndPrint $= fn.inc ||| fn.println # Calling fp.incAndPrint($x) has the same effect as calling fn.println(fn.inc($x))
fp.incAndPrint(2) # Prints 3
 
# The pow operator can be used to call a function multiple times in succession
# This works only with exponents >= 0 (If the exponent is 0 a function will be returned, that always returns VOID)
fp.voidFunc $= fn.inc ** 0
fp.voidFunc(2) # Returns VOID
 
fn.pow(fn.inc, 1)(2) # Returns 3
fn.pow(fn.inc, 2)(2) # Returns 4
fn.pow(fn.inc, 3)(2) # Returns 5
fn.pow(fn.inc, 10)(2) # Returns 12
</syntaxhighlight>
 
=={{header|langur}}==
User-defined and built-in functions can be called using parentheses.
Line 3,319 ⟶ 3,692:
 
<syntaxhighlight lang="langur">val .sum = foldfrom(
ffn(.sum, .i, .c) .sum + toNumbernumber(.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>
Line 3,330 ⟶ 3,703:
}
# unbounded list on keys bounded by closing parenthesis of sort</syntaxhighlight>
 
=={{header|Latitude}}==
 
Line 3,462 ⟶ 3,836:
 
* 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,482 ⟶ 3,856:
* Not explicitly.
* However, one can use <code>lambda</code>s to achieve the same effect.
 
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
Line 5,752 ⟶ 6,127:
macro definition is responsible for evaluating what it needs to. But macros likely
fall into a different category than the scope of this task.
 
=={{header|SmallBASIC}}==
<syntaxhighlight lang="basic">
func F1()
return 1
end
 
func F2(a)
return a + 1
end
 
func F3(a, b)
return a + b
end
 
func F4(byref a)
a = 5
return a + 1
end
 
sub S1(a, b)
print a, b
end
 
sub S2(byref a)
a = 5
end
 
var1 = 1
var2 = 2
 
' Functions return a result and return-value must be assigned to a variable
result = F1()
result = F2(var1)
result = F3(var1, var2)
' Parameters are passed by reference if byref is used in function definition
result = F4(var1) ' result = 6 and var1 = 5
 
' Subroutines can't return a result
S1(var1, var2)
' Parameters are passed by reference if byref is used in sub definition.
' This can be used to return a result indirectly
S2(var1) ' var1 = 5
 
' Functions and subroutines can take expressions as parameter
result = F2(1 + 2)
</syntaxhighlight>
 
 
=={{header|Smalltalk}}==
Line 6,085 ⟶ 6,508:
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,129 ⟶ 6,552:
50
</pre>
 
=={{header|XLISP}}==
<syntaxhighlight lang="lisp">; call a function (procedure) with no arguments:
885

edits