Jump to content

Call a function: Difference between revisions

Added Maple implementation.
(Perl - Updated for more correctness, legibility)
(Added Maple implementation.)
Line 854:
-- Built-in functions are not easily distinguishable from user-defined functions
</lang>
 
=={{header|Maple}}==
Calling a function with no arguments:<lang Maple> f()</lang>
Calling a function with a fixed number of arguments:<lang Maple>f(1,sin(x), g -> int(g(t),t=0..1)</lang>
Calling a function with optional arguments: <lang Maple>f(1, sin(x), g -> int(g(t),t=0..1)</lang>
Calling a function with a variable number of arguments: <lang Maple>f(1, sin(x), g -> int(g(t),t=0..1)</lang>
Calling a function with named arguments:<lang Maple>f(a,b,method = foo)</lang>
Calling a function in a statements context:<lang Maple>f(a); f(b);</lang>
Using a function in first-class context within an expression:<lang Maple>f(a) + g(b)</lang>
Obtaining the return value of a function:<lang Maple> x := f(1)</lang>
Distinguishing built-in functions and user-defined functions:
<lang Maple>> type( op, 'builtin' );
true
</lang>
Distinguishing subroutines and functions: There is no distinction.
 
Stating whether arguments are passed by value or by reference: All values are passed by value.
However, if an argument is a name, then it can be assigned to and, if a value is mutable (such as an array), then it can be modified by the function. This is implemented by function definition; there is no distinction when calling the function.
 
Partial application is supported by the <code>curry</code> and <code>rcurry</code> commands.
 
=={{header|Mathematica}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.