On Sun, May 17, 2009 at 07:41:45PM +0200, Moritz Lenz wrote:
: Hi,
: 
: (sorry for yet another p6l email mentioning junctions; if they annoy you
: just ignore this mail :-)
: 
: while reviewing some tests I found the "each() comprehension" in S02
: that evaded my attention so far.
: 
: Do we really want to keep such a rather obscure syntactic
: transformation? I find an explicit grep much more readable; if we want
: it to work in a more general case, it might become some kind of junction
: that, on autothreading, keeps a mapping between the original item and
: the new value, and on collapse returns all items for which the new value
: is true. Something along these lines:
: 
:  g(f(each(1..3))9
: becomes
:  g(each(1 => f(1), 2 => f(2), 3 => f(3)))
: becomes
:  each(1 => g(f(1)), 2 => g(f(2)), 3 => (g(f(3)))
: and on collapse returns
:  1..3.grep:{g(f($_))};
: 
: IMHO this would DWIM more in arbitrary code than the special syntactic
: form envisioned

Feel free either to whack it out and/or install each() as a conjectural
mapping junction that may be deferred till post-6.0.0.

: Also this part of S02 is rather obscure, IMHO:
: 
: >  In particular,
: >
: >    @result = each(@x) ~~ {...};
: >
: > is equivalent to
: >
: >    @result = @x.grep:{...};
: 
: Should it be @result = @x.grep:{ $_ ~~ ... } instead? Otherwise
: 
: 'each(@x) ~~ 1..3' would be transformed into '@x.grep:{1..3}', which
: would return the full list. (Or do adverbial blocks some magic smart
: matching that I'm not aware of?)

The grep itself does the smart matching:

    @dogs = grep Dog, @mammals;

Larry

Reply via email to