Function definition: Difference between revisions
Add SmallBASIC
(→{{header|BASIC}}: Added ANSI BASIC.) |
(Add SmallBASIC) |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 1,022:
The product of 9 times 3 is 27
</pre>
==={{header|SmallBASIC}}===
func multiply(a, b)
return a * b
end
print "2 * 3 = "; multiply(2, 3)
If function definition is only one line, <code>def</code> can be used:
def multiply(a, b) = a * b
print "2 * 3 = "; multiply(2, 3)
==={{header|True BASIC}}===
Line 1,219 ⟶ 1,235:
return a*b;
}</syntaxhighlight>
=={{header|Chapel}}==
<syntaxhighlight lang="text">
proc multiply(a, b)
{
return a * b;
}
Can require that the two arguments be of the same type.
<syntaxhighlight lang="text">
proc multiply(a : ?t ... 2)
{
return a(0) * a(1)
}
Will work on any type where the * operator is defined.
=={{header|ChucK}}==
Line 2,183 ⟶ 2,218:
=={{header|langur}}==
<syntaxhighlight>
val multiply = fn{*}
</syntaxhighlight>
<syntaxhighlight>
val multiply = fn a, b: a * b
</syntaxhighlight>
<syntaxhighlight>
val multiply = fn(a, b) { a * b }
</syntaxhighlight
▲.multiply(3, 4)</syntaxhighlight>
▲.multiply(3, 4)</syntaxhighlight>
▲<syntaxhighlight lang="langur">val .multiply = fn{*}
▲.multiply(3, 4)</syntaxhighlight>
▲<syntaxhighlight lang="langur">val .times3 = fn{* 3}
▲map .times3, [1, 2, 3]</syntaxhighlight>
=={{header|Lasso}}==
Line 2,825 ⟶ 2,840:
After a <tt>function</tt> has been activated, there must have be ''exactly one'' assignment to the (implicitly declared) variable bearing the same name as of the function.
Many processors do not comply with this specification, though, and allow ''overwriting'' the return value ''multiple'' times.
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
function multiply(a,b: real): real := a + b;
</syntaxhighlight>
=={{header|Perl}}==
|