Function definition: Difference between revisions

Content added Content deleted
Line 2,156: Line 2,156:
Functions defined with explicit parameters may be closures, and those defined with implied parameters are not.
Functions defined with explicit parameters may be closures, and those defined with implied parameters are not.


Langur functions are first-order. They are pure in terms of setting values, though not in terms of I/O.
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 ===
Line 2,171: Line 2,171:
Operator implied functions are built using an infix operator between curly braces on an f token.
Operator implied functions are built using an infix operator between curly braces on an f token.


{{works with|langur|0.6.6}}
<syntaxhighlight lang="langur">val .multiply = f{x}
<syntaxhighlight lang="langur">val .multiply = f{x}
.multiply(3, 4)</syntaxhighlight>
.multiply(3, 4)</syntaxhighlight>
Line 2,178: Line 2,177:
These are built with an infix operator and one operand inside the f{...} tokens.
These are built with an infix operator and one operand inside the f{...} tokens.


{{works with|langur|0.8.11}}
<syntaxhighlight lang="langur">val .times3 = f{x 3}
<syntaxhighlight lang="langur">val .times3 = f{x 3}
map .times3, [1, 2, 3]</syntaxhighlight>
map .times3, [1, 2, 3]</syntaxhighlight>

=== impure functions (I/O) ===
Impure functions must be declared as such.
<syntaxhighlight>val .writeit = impure f(.x) { writeln .x }</syntaxhighlight>

Impure functions cannot be passed to pure functions.


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