This and other RFCs are available on the web at
  http://dev.perl.org/rfc/

=head1 TITLE

Short-circuiting C<grep> and C<map> with C<last>

=head1 VERSION

  Maintainer: Garrett Goebel <[EMAIL PROTECTED]>
  Date: 6 Sep 2000
  Mailing List: [EMAIL PROTECTED]
  Version: 1
  Number: 199
  Status: Developing

=head1 ABSTRACT

Allow functions like C<grep> and C<map> with implicit loop blocks to
be short circuited with C<last>.

=head1 DESCRIPTION

It'd be nice if one could use C<grep> to find out if a value is
held in a list without having to iterate through every element
of said list. I'm sure others can figure out their own uses for
short-circuiting C<grep> and C<map>.

Adoption of this suggestion would create problems with any Perl 5 code
that is so strange as to currently use C<last> within a C<grep> or C<map>
block. Hmm, I don't know how this could be worked around other than to
have the Perl 5->6 translation label loops and C<last>s whenever C<last>
is found within a C<grep> or C<map> block. If someone has a better idea
please suggest it.

Neither Tom Christiansen nor Jarkko Hietaniemi profess to know why the
suggestion with regards to C<grep> hasn't already been implemented.
Perhaps it has to do with the fact that the blocks in C<grep> and C<map>
are only implicitly loops, where as C<while>, C<until>, C<for>, and 
C<foreach> are explicitly loops.

It might therefore follow that one should also be able to lable C<grep>
and C<map> statements, as they are implicit loops. Are there any other
similar built-in functions?

If there is strong sentiment that one or the other of C<grep> and C<map>
should(n't) me allowed to short circuit with C<last>, then let me know
and I'll break this into 2 RFC's.

=head1 IMPLEMENTATION

I haven't a clue. Please feel free to suggest one for the next revision.

=head1 REFERENCES

Ideas that offer alternative routes to similar functionality:

RFC 22: Builtin switch statement

RFC ??: Damian Conway's forthcoming superpositions RFC


Reply via email to