Function definition: Difference between revisions

m
no edit summary
(→‎{{header|BASIC}}: Added ANSI BASIC.)
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 1,219:
return a*b;
}</syntaxhighlight>
 
=={{header|Chapel}}==
 
<syntaxhighlight lang="text">
 
proc multiply(a, b)
{
return a * b;
}
.multiply(3, 4)</syntaxhighlight>
 
Can require that the two arguments be of the same type.
<syntaxhighlight lang="text">
proc multiply(a : ?t ... 2)
{
return a(0) * a(1)
}
</syntaxhighlight>
Will work on any type where the * operator is defined.
 
=={{header|ChucK}}==
Line 2,190 ⟶ 2,209:
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>
 
=== 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>
 
6

edits