Function definition: Difference between revisions

m
Semi-automated edit: Bash -> UNIX Shell
(Add Brat solution)
m (Semi-automated edit: Bash -> UNIX Shell)
Line 94:
print mul(5, 6)
}</lang>
 
=={{header|Bash}}==
return an exit code
<lang bash>multiply() {
return $(($1 * $2))
 
multiply 5 6
echo $?</lang>
echo the result
<lang bash>multiply() {
echo -n $(($1 * $2))
 
echo $(multiply 5 6)</lang>
 
=={{header|BASIC}}==
Line 143 ⟶ 128:
 
Another advantage of macros is that they work with all types alike. For example, the above macro can be used both to multiply double values (like the function above), and to multiply int values (giving an int, which the function doesn't).
 
=={{header|C sharp|C#}}==
 
<lang csharp>static double multiply(double a, double b)
return a * b;
}</lang>
 
Anonymous function:
 
<lang csharp>Func<double, double, double> multiply = ((a,b) => a*b);</lang>
 
=={{header|C++}}==
Line 164 ⟶ 160:
 
Of course, both inline and template may be combined (the <tt>inline</tt> then has to follow the <tt>template&lt;...&gt;</tt>), but since templates have to be in the header anyway (while the standard allows them to be compiled separately using the keyword <tt>export</tt>, almost no compiler implements that), the compiler usually can inline the template even without the keyword.
 
=={{header|C sharp|C#}}==
 
<lang csharp>static double multiply(double a, double b)
return a * b;
}</lang>
 
Anonymous function:
 
<lang csharp>Func<double, double, double> multiply = ((a,b) => a*b);</lang>
 
=={{header|Clojure}}==
Line 256 ⟶ 241:
=={{header|Erlang}}==
<lang erlang>multiply(A,B) -> A*B.</lang>
 
=={{header|F Sharp|F#}}==
The default will be an integer function but you can specify other types as shown:
<lang fsharp>let multiply x y = x * y // integer
let fmultiply (x : float) (y : float) = x * y</lang>
 
=={{header|Factor}}==
Line 320 ⟶ 310:
end function multiply
end module elemFunc</lang>
 
=={{header|F Sharp|F#}}==
The default will be an integer function but you can specify other types as shown:
<lang fsharp>let multiply x y = x * y // integer
let fmultiply (x : float) (y : float) = x * y</lang>
 
=={{header|GML}}==
Line 356 ⟶ 341:
multiply = a * b
END</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
{{works with|Unicon}}
<lang Icon>procedure multiply(a,b)
return a * b
end</lang>
 
=={{header|IDL}}==
Line 382 ⟶ 373:
 
This will return a scalar if given scalars, if given one- or two-dimensional arrays it will return the matrix-product of these arrays. E.g. if given two three-element one-dimensional arrays (i.e. vectors), this will return a 3x3 matrix.
 
=={{header|Icon}} and {{header|Unicon}}==
{{works with|Unicon}}
<lang Icon>procedure multiply(a,b)
return a * b
end</lang>
 
=={{header|Inform 7}}==
Line 430 ⟶ 415:
output :x * :y
end</lang>
=={{header|BashLSE64}}==
<lang lse64>multiply : *
multiply. : *. # floating point</lang>
 
=={{header|Lua}}==
<lang Lua>function multiply( a, b )
Line 437 ⟶ 426:
=={{header|Lucid}}==
<lang lucid>multiply(x,y) = x * y</lang>
 
=={{header|LSE64}}==
<lang lse64>multiply : *
multiply. : *. # floating point</lang>
 
=={{header|M4}}==
Line 957 ⟶ 942:
=={{header|Toka}}==
<lang toka>[ ( ab-c ) * ] is multiply</lang>
 
=={{header|LSE64UNIX Shell}}==
{{works with|Bash}}
 
return an exit code
<lang bash>multiply() {
return $(($1 * $2))
 
multiply 5 6
echo $?</lang>
echo the result
<lang bash>multiply() {
echo -n $(($1 * $2))
 
echo $(multiply 5 6)</lang>
 
=={{header|Ursala}}==
Anonymous user