develooper Front page | perl.perl6.language | Postings from December 2008

Re: [perl #61126] return should apply to the lexically enclosing routine, map is no exception

Thread Next
From:
Carl Mäsak
Date:
December 7, 2008 09:10
Subject:
Re: [perl #61126] return should apply to the lexically enclosing routine, map is no exception
Message ID:
16d769b70812070910l32c98972h5f76c9124f6d1bc4@mail.gmail.com
Daniel, in rakudobug ticket [perl #61126] (>):
> The following two snippets of code are supposed to behave the same:
>
> sub bar($code) { $code() };
> sub foo { bar { return 1 }; return 2; }; say foo;
>
> and
>
> sub foo { map { return 1 }, 1; return 2 }; say foo;
>
> both are supposed to return "1".
>
> For some reason, map is being handled specially, while it is supposed to
> be dispatched as any regular sub.

The above reasoning raises the following question for me: how do I
return from a sub or a method from within a map block?

(Let's say, for the sake of discussion, that there is a legitimate
reason to do this. I know that "use a for loop if you want that kind
of side effect" is a reasonable purist answer.)

// Carl

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