Function definition: Difference between revisions
Content added Content deleted
(Add Brat solution) |
m (Semi-automated edit: Bash -> UNIX Shell) |
||
Line 94: | Line 94: | ||
print mul(5, 6) |
print mul(5, 6) |
||
}</lang> |
}</lang> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
Line 143: | Line 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). |
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++}}== |
=={{header|C++}}== |
||
Line 164: | Line 160: | ||
Of course, both inline and template may be combined (the <tt>inline</tt> then has to follow the <tt>template<...></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. |
Of course, both inline and template may be combined (the <tt>inline</tt> then has to follow the <tt>template<...></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|Clojure}}== |
=={{header|Clojure}}== |
||
Line 256: | Line 241: | ||
=={{header|Erlang}}== |
=={{header|Erlang}}== |
||
<lang erlang>multiply(A,B) -> A*B.</lang> |
<lang erlang>multiply(A,B) -> A*B.</lang> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
Line 320: | Line 310: | ||
end function multiply |
end function multiply |
||
end module elemFunc</lang> |
end module elemFunc</lang> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|GML}}== |
=={{header|GML}}== |
||
Line 356: | Line 341: | ||
multiply = a * b |
multiply = a * b |
||
END</lang> |
END</lang> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|IDL}}== |
=={{header|IDL}}== |
||
Line 382: | Line 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. |
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|Inform 7}}== |
=={{header|Inform 7}}== |
||
Line 430: | Line 415: | ||
output :x * :y |
output :x * :y |
||
end</lang> |
end</lang> |
||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
<lang Lua>function multiply( a, b ) |
<lang Lua>function multiply( a, b ) |
||
Line 437: | Line 426: | ||
=={{header|Lucid}}== |
=={{header|Lucid}}== |
||
<lang lucid>multiply(x,y) = x * y</lang> |
<lang lucid>multiply(x,y) = x * y</lang> |
||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|M4}}== |
=={{header|M4}}== |
||
Line 957: | Line 942: | ||
=={{header|Toka}}== |
=={{header|Toka}}== |
||
<lang toka>[ ( ab-c ) * ] is multiply</lang> |
<lang toka>[ ( ab-c ) * ] is multiply</lang> |
||
⚫ | |||
{{works with|Bash}} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|Ursala}}== |
=={{header|Ursala}}== |