Call a function: Difference between revisions

Content added Content deleted
(→‎{{header|Matlab/Octave}}: call a function)
Line 202: Line 202:


=={{header|Mathematica}}==
=={{header|Mathematica}}==
<lang Mathematica>Calling a function that requires no arguments:
Calling a function that requires no arguments:
<lang Mathematica>f[]</lang>
f[]


Calling a function with a fixed number of arguments:
Calling a function with a fixed number of arguments:
<lang Mathematica>f[1,2]</lang>
f[1,2]


Calling a function with optional arguments:
Calling a function with optional arguments:
f[1,Option1->True]
<lang Mathematica>f[1,Option1->True]</lang>


Calling a function with a variable number of arguments:
Calling a function with a variable number of arguments:
f[1,Option1->True]
<lang Mathematica>f[1,Option1->True]
f[1,Option1->True,Option2->False]
f[1,Option1->True,Option2->False]</lang>


Calling a function with named arguments:
Calling a function with named arguments:
f[Option1->True,Option2->False]
<lang Mathematica>f[Option1->True,Option2->False]</lang>


Using a function in statement context:
Using a function in statement context:
f[1,2];f[2,3]
<lang Mathematica>f[1,2];f[2,3]</lang>


Using a function in first-class context within an expression:
Using a function in first-class context within an expression:
(#^2)&[3];
<lang Mathematica>(#^2)&[3];</lang>


The return value of a function can be formally extracted using Return[]
The return value of a function can be formally extracted using Return[]
Built-in functions names by convention start with a capital letter.
Built-in functions names by convention start with a capital letter.
No formal distinction between subroutines and functions.
No formal distinction between subroutines and functions.
Arguments can be passed by value or by reference.</lang>
Arguments can be passed by value or by reference.


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==