Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

&wrap, &call and goto &sub

4 views
Skip to first unread message

Autrijus Tang

unread,
Mar 16, 2005, 7:46:03 AM3/16/05
to perl6-l...@perl.org
Just a quick question. In Pugs t/op/arith.t we have:

sub tryeq_sloppy ($lhs, $rhs, ?$todo1 = '') {
...
ok($lhs==$rhs,$ todo);
...
}

But it breaks the $?CALLER based error reporting, because
it introduces another layer of caller.

In Perl5, I'd do this:

{ local @_ = ($lhs == $rhs, $todo); goto &ok; }

Does that form still work with Perl 6? Or should I use this?

{ local &_ := &ok; call($lhs == $rhs, $todo); }

However, I did not see A/E/S06 specifying that call() will assume the
&goto semantic of erasing itself from the caller chain, so I hesitate
to implement it that way.

Is using wrap/call the correct choice here, or is there another way
to do it that I missed?

Thanks,
/Autrijus/

Autrijus Tang

unread,
Mar 16, 2005, 7:48:12 AM3/16/05
to Autrijus Tang, perl6-l...@perl.org
On Wed, Mar 16, 2005 at 08:46:03PM +0800, Autrijus Tang wrote:
> Does that form still work with Perl 6? Or should I use this?
>
> { local &_ := &ok; call($lhs == $rhs, $todo); }

s/local/my/ of course. :-)

Thanks,
/Autrijus/

Larry Wall

unread,
Mar 16, 2005, 1:24:16 PM3/16/05
to perl6-l...@perl.org
On Wed, Mar 16, 2005 at 08:46:03PM +0800, Autrijus Tang wrote:
: Just a quick question. In Pugs t/op/arith.t we have:

:
: sub tryeq_sloppy ($lhs, $rhs, ?$todo1 = '') {
: ...
: ok($lhs==$rhs,$ todo);
: ...
: }
:
: But it breaks the $?CALLER based error reporting, because
: it introduces another layer of caller.
:
: In Perl5, I'd do this:
:
: { local @_ = ($lhs == $rhs, $todo); goto &ok; }
:
: Does that form still work with Perl 6?

We will have some equivalent way to do an explicit substituting
tail call, but perhaps not with that syntax, since passing @_ through
is kind of bogus these days. Probably we end up with

&func.goto(@args)

or some such.

: Or should I use this?


:
: { local &_ := &ok; call($lhs == $rhs, $todo); }
:
: However, I did not see A/E/S06 specifying that call() will assume the
: &goto semantic of erasing itself from the caller chain, so I hesitate
: to implement it that way.

call() doesn't erase itself from the call chain, but it does "cloak"
itself so that CALLER doesn't see it by default. (Presumably there's
an option to caller() that makes hidden frames visible.) The whole
point of wrappers is that the aren't realy there in some logical sense.

: Is using wrap/call the correct choice here, or is there another way


: to do it that I missed?

wrap/call should do what you want there, but if you want to hack in
&func.goto, that'd be good too.

Larry

Autrijus Tang

unread,
Mar 16, 2005, 1:38:45 PM3/16/05
to perl6-l...@perl.org

Done as r804. It also passes the expected context ("want") of its
original caller to &func, which I assume is the correct behaviour.

Thanks,
/Autrijus/

Larry Wall

unread,
Mar 16, 2005, 1:51:18 PM3/16/05
to perl6-l...@perl.org
On Thu, Mar 17, 2005 at 02:38:45AM +0800, Autrijus Tang wrote:

Yes.

Larry

0 new messages