develooper Front page | perl.perl6.language | Postings from July 2005

Tail method calls, can(), and pre-currying

Thread Next
Brent 'Dax' Royal-Gordon
July 20, 2005 18:44
Tail method calls, can(), and pre-currying
Message ID:
<brentdax> Is there a Perl 6 tail call syntax, and if so is it
implemented in Pugs?
<autrijus> &sub.goto(...);
<autrijus> and yes.
<brentdax> Oh...are tail method calls possible?
<autrijus> tail method calls. hrmph.

I have a few methods where I'd like to perform tail calls into another
object's methods.  If I were calling one of my own methods, I'd
probably use &meth.goto($?SELF, *@args) as Autrijus suggested before,
but these are calls into another object, based on its runtime class.

As far as I can tell, the easiest way to do this in Perl 6 is thus:

    $obj.can('meth').goto($obj, *@args);

Besides the fact that this isn't possible in current Pugs (which seems
to lack a can() method), it has several other problems: it's too long,
the method name is being treated as a string, the object is included
twice, it will fail silently if $obj doesn't have a `meth` method, and
so on.

One suggestion was a tweak of `can`'s definition: instead of returning
a reference to the method, it returns one with the invocant already
curried into it.  Thus, the above becomes this:


While quite a bit better, this still has many of the problems I
mentioned before.  My recommendation is thus:


The .\meth takes a precurried reference to the `meth` method (throwing
an appropriate tantrum if `meth` doesn't exist), which can then be
treated like any other subroutine reference, in this case being
invoked as a tail call.

Of course, this adds *another* piece of syntax to an already large
language, so I'm not sure if it's a good idea.

Am I missing something?  How do you think a tail method call should be

Brent 'Dax' Royal-Gordon <>
Perl and Parrot hacker

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About