<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, [EMAIL PROTECTED]) 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, [EMAIL PROTECTED]);
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:
$obj.can('meth').goto([EMAIL PROTECTED]);
While quite a bit better, this still has many of the problems I
mentioned before. My recommendation is thus:
$obj.\meth.goto([EMAIL PROTECTED]);
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
performed?
--
Brent 'Dax' Royal-Gordon <[EMAIL PROTECTED]>
Perl and Parrot hacker