Function definition: Difference between revisions

→‎{{header|langur}}: modified to suit task description
(→‎{{header|langur}}: modified to suit task description)
Line 2,202:
 
=={{header|langur}}==
multiply(3, 4)</syntaxhighlight>
Langur functions are first-order. They are pure in terms of setting values and in terms of I/O (unless declared impure).
val multiply = fn{*}
multiply(3, 4)</syntaxhighlight>
 
map times3, [1, 2, 3]</syntaxhighlight>
A return statement may be used, but a function's last value is its implicit return value.
val multiply = fn a, b: a * b
</syntaxhighlight>
 
=== parameters ===
Parameters are defined within parentheses after the fn token. To specify no parameters, use an empty set of parentheses.
<syntaxhighlight lang="langur">val multiply = fn(x, y) { x * y }
multiply(3, 4)</syntaxhighlight>
 
=== operator implied functions ===
Operator implied functions are built using an infix operator between curly braces on an fn token.
 
<syntaxhighlight lang="langur">val multiply = fn{*}
multiply(3, 4)</syntaxhighlight>
 
=== nil left partially implied functions ===
These are built with an infix operator and a right-hand operand inside the fn{ } tokens.
 
<syntaxhighlight lang="langur">val times3 = fn{* 3}
map times3, [1, 2, 3]</syntaxhighlight>
 
=== impure effects ===
Functions with impure effects must be declared as such, using fn*.
<syntaxhighlight>
val writeitmultiply = fn*(xa, b) { writelna * xb }
</syntaxhighlight>
 
Impure functions cannot be passed to pure functions.
 
=={{header|Lasso}}==
1,007

edits