Re: return() in pointy blocks
by Matt Fowles other posts by this author
Jun 7 2005 9:37AM messages near this date
return() in pointy blocks
|
Re: return() in pointy blocks
Ingo~
On 6/7/05, Ingo Blechschmidt <iblech@[...].de> wrote:
> Hi,
>
> 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.
It seems to me that what you are asking for has the potential to cause
some vary large unexpected jumps down the stack. That said, I would
want the pointy subs in for loops to ask this way, so maybe this is
just one of those things that one has to be ware of.
Matt
--
"Computer Science is merely the post-Turing Decline of Formal Systems Theory."
-???
Thread:
Ingo Blechschmidt
Matt Fowles
Luke Palmer
=22TSa_=28Thomas_Sandla=DF=29=22
=22TSa_=28Thomas_Sandla=DF=29=22
Larry Wall
"TSa (Thomas Sandlaß)"
Larry Wall
Matt Fowles
|