Call a function: Difference between revisions

partial application
(partial application)
Line 12:
* Distinguishing subroutines and functions
* Stating whether arguments are [[:Category:Parameter passing|passed]] by value or by reference
* Is partial application possible and how
 
This task is ''not'' about [[Function definition|defining functions]].
Line 299 ⟶ 300:
 
=={{header|Perl 6}}==
Fundamentally, nearly everything you do in Perl  6 is a function call if you look hard enough.
At the lowest level, a function call merely requires a reference to any
kind of invokable object, and a call to its <tt>postcircumfix:&lt;( )&gt;</tt> method.
Line 337 ⟶ 338:
to dispatch to the same set of functions that a function call of that name
would invoke. That's why there's a dispatcher, after all. Methods are declared
with a different keyword, <tt>method</tt>, in Perl  6, but all that does is
install the actual function into a metaclass. Once it's there, it's merely
a function that expects its first argument to be the invocant object. Hence we
Line 345 ⟶ 346:
multiply dispatched to all lexically scoped candidates for the function. Hence
the candidate list is bound early, and the function itself can be bound early
if the type is known. Perl  6 maintains a clear distinction between early-bound
linguistic constructs that force Perlish semantics, and late-bound OO dispatch
that puts the objects and/or classes in charge of semantics. (In any case, <tt>&foo</tt>,
Line 388 ⟶ 389:
on whether a signature accepts a list at that position in the argument list, but
describing that is not the purpose of this task. Suffice to say that we assume here that the
foo function is declared with a signature of the form (*@params). The calls above might be interpreted as having a single array argument if the signature indicates a normal parameter instead of a variadic one. What you cannot do in Perl  6 (unlike Perl  5) is pass an array as several fixed arguments. By default it must either represent a single argument, or be part of a variadic list. You can force the extra level of argument list interpolation using a prefix <tt>|</tt> however:
 
<lang perl6>my @args = 1,2,3;
Line 416 ⟶ 417:
 
There is no difference between calling builtins and user-defined functions and operators (or
even control stuctures). This was a major design goal of Perl  6, and apart from a very few
low-level primitives, all of Perl  6 can be written in Perl  6.
 
There is no difference between calling subroutines and functions in Perl  6, other than that
calling a function in void context that has no side effects is likely to get you a "Useless use of..." warning.
And, of course, the fact that pure functions can participate in more optimizations such as constant folding.