Function definition: Difference between revisions

Content added Content deleted
(→‎{{header|BASIC}}: Added ANSI BASIC.)
Line 2,190: Line 2,190:
Parameters are defined within parentheses after the fn token. To specify no parameters, use an empty set of parentheses.
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 }
<syntaxhighlight lang="langur">val .multiply = fn(.x, .y) { .x * .y }
.multiply(3, 4)</syntaxhighlight>

=== curly braces ===
A function body may use curly braces, but it is not required if it is a single expression.
<syntaxhighlight lang="langur">val .multiply = fn(.x, .y) .x * .y
.multiply(3, 4)</syntaxhighlight>
.multiply(3, 4)</syntaxhighlight>