ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl6-language
perl6-language
Re: return() in pointy blocks
by Ingo Blechschmidt other posts by this author
Jun 7 2005 10:11AM messages near this date
Re: return() in pointy blocks | return() in pointy blocks
Hi,

Matt Fowles wrote:
>  On 6/7/05, Ingo Blechschmidt <iblech@[...].de> wrote:
> >   sub foo (Code $code) {
> >     my $return_to_caller = -> $ret { return $ret };
> > 
> >     $code($return_to_caller);
> >     return 23;
> >   }
> > 
> >   sub bar (Code $return) { $return(42) }
> > 
> >   say foo &bar; # 42 or 23?
> > 
> > I think it should output 42, as the return() in the pointy
> > block $return_to_caller affects &foo, not the pointy block.
> > To leave a pointy block, one would have to use leave(), right?
>  
>  I don't like this because the function bar is getting oddly
>  prematurely halted.  If bar had read
>  
>  sub bar(Code $moo) {
>      $moo(13);
>      save_the_world();
>  }
>  
>  it would not have gotten to save the world.  One might argue that $moo
>  could throw an exception, but bar has a way to catch that.

yep. $moo(13) will never return.

But this is not specific to pointy blocks: Consider
  bar &return;

>  It seems to me that what you are asking for has the potential to cause
>  some vary large unexpected jumps down the stack.

Yep.

>  so maybe this is just one of those things that one has to be ware of.

I think the reponsibility is at the user using &return or other
evil Codes (like, as in the example, ->  $val { return $val }), not the
innocent subroutine programmer (&bar)) -- if you play with
continuations, you know what might happen. But they can be very useful,
too! :)


--Ingo

-- 
Linux, the choice of a GNU | Failure is not an option. It comes bundled 
generation on a dual AMD   | with your Microsoft product.  
Athlon!                    | 

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved