On Mon, Sep 11, 2000 at 05:31:33PM -0400, 'John Porter' wrote:
> Garrett Goebel wrote:
> > 
> > I'd be surprised if 
> > 
> > sub mygrep (&@) {
> >   my ($coderef, @list, @stack) = @_;
> >   &$coderef and push(@stack, $_)  foreach (@list);
> >   return @stack;
> > }
> > 
> > @a = mygrep { return ($_ <= 2) ? 1 : 0 } (1, 2, 3, 2, 1);
> > print "\@a = @a\n";
> > 
> > Resulted in: @a = 
> > Instead of the current Perl 5:  @a = 1 2 2 1
> 
> Yes!  *Exactly* my point!  Blocks should quack the same whether
> I pass them to the built-in grep or to my own sub; i.e. they're
> anonymous subs, not some magico-special "looping" blocks.

Allow me to repeat: instead of trying to shoehorn (or piledrive) new
semantics onto existing keywords/syntax, let's create something new.
The blocks of grep/map/... are special.  They are not quite looping
blocks, they are not quite sub blocks, they are different.  Well, to
be frank they are just very plain, ordinary, blocks that return their
last value, but if we want to introduce both flow control
(short-circuiting) and as a derived requirement, a return value
(was the last test a success or a failure), they definitely begin to
become not your ordinary blocks.  I do not think the existing arsenal
of keywords/syntax is enough to cover all the behaviour we are after.
The 'pass' keyword someone suggested has potential (when combined with
allowing last -- and next -- to work on these mongrel blocks).

-- 
$jhi++; # http://www.iki.fi/jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen

Reply via email to