Function definition: Difference between revisions
→{{header|langur}}
Langurmonkey (talk | contribs) |
Langurmonkey (talk | contribs) |
||
Line 2,150:
=={{header|langur}}==
Langur functions are first-order. They are pure in terms of setting values and in terms of I/O (unless declared impure).▼
A function body may use curly braces, but it is not required if it is a single expression.▼
A return statement may be used, but a function's last value is its implicit return value.
▲Langur functions are first-order. They are pure in terms of setting values and in terms of I/O (unless declared impure).
▲=== explicit parameters ===
▲Explicit parameters are defined with parentheses after the f token, with no spacing. To specify no parameters, use an empty set of parentheses.
▲<syntaxhighlight lang="langur">val .multiply = f(.x, .y) .x x .y
.multiply(3, 4)</syntaxhighlight>
===
▲A function body may use curly braces, but it is not required if it is a single expression.
<syntaxhighlight lang="langur">val .multiply =
.multiply(3, 4)</syntaxhighlight>
=== operator implied functions ===
Operator implied functions are built using an infix operator between curly braces on an
<syntaxhighlight lang="langur">val .multiply =
.multiply(3, 4)</syntaxhighlight>
=== nil left partially implied functions ===
These are built with an infix operator and
<syntaxhighlight lang="langur">val .times3 =
map .times3, [1, 2, 3]</syntaxhighlight>
=== impure functions (I/O) ===
Impure functions must be declared as such.
<syntaxhighlight>val .writeit = impure
Impure functions cannot be passed to pure functions.
|