On Tue, 2004-08-31 at 14:11, Sean O'Rourke wrote:
> At Tue, 31 Aug 2004 13:23:04 -0400,
> [EMAIL PROTECTED] (Aaron Sherman) wrote:
> > I would think you actually want to be able to define grep, map, et al.
> > in terms of the mechanism for unraveling, and just let the optimizer
> > collapse the entire pipeline down to a single map.
> 
> Even for map and grep this is a bit trickier, since map can produce
> zero or more values for each input value, and calls its body in list
> context, whereas grep produces zero or one value, and gets called in
> scalar context.

You're confusing two stages of grep's operation. grep's body is called
in boolean context, but that has NOTHING to do with the return value,
which is a list of zero or one elements like so:

        sub grep (&code, [EMAIL PROTECTED]) {
                map { if code($_) { $_ } else { () } } @list;
        }

That said, I skipped over a MAJOR point in my original reply, and it
must be said that in the case of map, you need iterators in order to do
the job correctly. map actually needs to return an object which, while
it can be treated as a list, is actually just an iterator object which
remembers the input list and transform closure.

Once you do that, you get cheap pipelining, as the major cost isn't the
construction of the temporary lists in Perl 5, it's POPULATING the
temporary lists. Constructing an iterator in Perl 6 means no population.
                
-- 
â 781-324-3772
â [EMAIL PROTECTED]
â http://www.ajs.com/~ajs

Reply via email to