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

Re: return() in pointy blocks

Thread Previous | Thread Next
From:
=?ISO-8859-1?Q?=22TSa_=28Thomas_Sandla=DF=29=22?=
Date:
June 8, 2005 04:52
Subject:
Re: return() in pointy blocks
Message ID:
42A6DC06.10807@orthogon.com
Piers Cawley wrote:
> My preference is for:
> 
>     Boo
>     Boo
>     Can't dereferene literal numeric literal 42 as a coderef.

How do you reach the second 'Boo'? Iff -> does not create a Sub
but a Block instance then Luke's code can be interpreted as a
much smarter version of

    sub foo()
    {
        enter: 42;
        if $?RETURN_LABEL { goto $?RETURN_LABEL }
        return;
    }

     say "Boo!";
     say goto foo::enter; # goto sets up $?RETURN_LABEL
     say "after goto";

which of course prints

    Boo
    42
    after goto

The smartness is in the value that &prefix:{'->'} returns
while in the snippet above it is explicitly coded.

Or do I completely misunderstand the distinction between
blocks and closures?
-- 
TSa (Thomas SandlaƟ)



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About