Function definition: Difference between revisions

Content added Content deleted
(→‎{{header|langur}}: modified to suit task description)
Line 2,202: Line 2,202:


=={{header|langur}}==
=={{header|langur}}==
<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{*}
</syntaxhighlight>


<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>
<syntaxhighlight>
val writeit = fn*(x) { writeln x }
val multiply = fn(a, b) { a * b }
</syntaxhighlight>
</syntaxhighlight>

Impure functions cannot be passed to pure functions.


=={{header|Lasso}}==
=={{header|Lasso}}==