Just to point out that it's probably worth going back and rereading the earlier iterations of this discussion, in December 2002 (subject: "purge: the opposite of grep") and November 2005 (subject: "Classification syntax"). That way, those who repeat history are condemned to study it. ;-)

In summary, when we last left this discussion, Larry was inclined to retain the name 'grep', and to add a 'classify' built-in that would allow positional or named partitioning of a list. For example (in updated syntax):

    (:@sheep, :@goats) := classify { /baaa/ ?? 'sheep' !! 'goats' } @list;

    (@x, @y, @huh).pairs := classify { /she/ ?? 0 !! /he/ ?? 1 !! 2 } @list;

        = classify { /<[EMAIL PROTECTED]>/ ?? 'perl' !! /<[()]>/ ?? 'lisp' !! 
'???' }

In other words, classify() takes a list of values, examines each in turn, and ascribes a "label" value to it. The call returns a list of pairs, where each pair key is one of the label values and each pair value is an array of all the list values that were ascribed that label.

Personally, I don't have a problem with us keeping 'grep'. However, if we do decide to change the name, I suspect 'keep' might be readable, short, SWIM, and not confused with other operations:

    my @evens = keep { $^num % 2 == 0 } @numbers;


Reply via email to