Anonymous user
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
At the lowest level, a function call merely requires a reference to any
kind of invokable object, and a call to its <tt>postcircumfix:<( )></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
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
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
<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
low-level primitives, all of Perl
There is no difference between calling subroutines and functions in Perl
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.
|