Call a function: Difference between revisions
m
Fix Perl6 -> Raku in comments
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
Thundergnat (talk | contribs) m (Fix Perl6 -> Raku in comments) |
||
Line 3,819:
(formerly Perl 6)
===Theory===
Fundamentally, nearly everything you do in
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 3,857:
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
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 3,865:
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.
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 3,908:
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
<lang perl6>my @args = 1,2,3;
Line 3,936:
There is no difference between calling builtins and user-defined functions and operators (or
even control stuctures). This was a major design goal of
low-level primitives, all of
There is no difference between calling subroutines and functions in
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.
|