Function definition: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) |
Langurmonkey (talk | contribs) (→{{header|langur}}: modified to suit task description) |
||
Line 2,202: | Line 2,202: | ||
=={{header|langur}}== |
=={{header|langur}}== |
||
⚫ | |||
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{*} |
|||
⚫ | |||
⚫ | |||
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 } |
|||
⚫ | |||
=== 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{*} |
|||
⚫ | |||
=== 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} |
|||
⚫ | |||
=== impure effects === |
|||
Functions with impure effects must be declared as such, using fn*. |
|||
<syntaxhighlight> |
<syntaxhighlight> |
||
val |
val multiply = fn(a, b) { a * b } |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
Impure functions cannot be passed to pure functions. |
|||
=={{header|Lasso}}== |
=={{header|Lasso}}== |