Jump to content

Call a function: Difference between revisions

GP
(→‎{{header|Perl 6}}: mention arglist interpolation via |)
(GP)
Line 83:
 
There are no ''differences between calling subroutines and functions'' because J defines neither <code>subroutines</code> nor <code>functions</code>. Instead, J defines <code>verbs</code>, <code>adverbs</code>, and <code>conjunctions</code> which for the purpose of this task are treated as functions.
 
=={{header|PARI/GP}}==
Calling a function is done in GP by writing the name of the function and the arguments, if any, in parentheses. As of version 2.5.0, function calls must use parentheses; some earlier versions allowed functions with an arity of 0 to be called without parentheses. However built-in constants (which are implicit functions of the current precision) can still be called without parentheses.
 
Optional arguments can be skipped, leaving commas in place. Trailing commas can be dropped.
 
Functions can be used when statements would be expected without change.
<lang parigp>f(); \\ zero arguments
sin(Pi/2); \\ fixed number of arguments
Str("gg", 1, "hh"); \\ variable number of arguments
(x->x^2)(3); \\ first-class
x = sin(0); \\ get function value</lang>
 
Built-in functions are like user-defined functions in current versions. In older versions built-in functions cannot be passed as closures.
 
Most arguments are passed by reference. Some built-in functions accept arguments (e.g., flags) that are not <code>GEN</code>s; these are passed by value or reference depending on their [[C]] type. See the User's Guide to the PARI Library section 5.7.3, "Parser Codes".
 
=={{header|Perl 6}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.