At 5:48 PM -0400 9/19/06, Bob Rogers wrote:
   From: [EMAIL PROTECTED]
   Date: Tue, 19 Sep 2006 14:26:30 -0400

   As a random alternative, I note that Ruby's analog to grep is called
   "find_all" (though it also has a "grep" that behaves differently from
   Perl's).  Personally, I'm not enamored of "filter" because it has
   connotations of removal...

Hmm.  Is this because Perl 5 grep can be used to modify a list in place?
Does Perl 6 grep also allow that?  The Lisp equivalent is remove-if-not,
which otherwise seems like a perfect description of what Perl grep does.

AFAIK, none of the things we are talking about will modify a list in place. Rather, they are all pure functions that take a list and a keep-what-matches condition as arguments and return a new list. And so they should remain. Modify in place is as simple as assigning the new list to the old variable.

   On 9/19/06, Jonathan Scott Duff <[EMAIL PROTECTED]> wrote:
   > . . .
   >
   > That said, I'm in favor of the term "filter" because, as Damian
   > mentioned, that term is used in several other languages.

In that vein, "select" from SQL should also be mentioned.  (I'm not so
sure that "filter" is broadly standard, as Damian asserts, but maybe I
haven't used enough languages.)

FYI, if you want to talk about SQL or the relational data model, in that context, both "select"/"project" and "where"/"restrict" perform analagous functions, doing filtering of sorts, but in different dimensions. The "select"/"project" takes a subset of the original table's/relation's columns/attributes, and the "where"/"restrict" takes a subset of the original table's/relation's rows/tuples. Its the difference between a vertical slice and a horizontal slice.

In Perl terms, (assuming an array of hashes), the "project" is like a hash slice; eg:

  my @projection = @original.map:{ {$_.<a b c>} };

Whereas, the "restrict" is like a grep; eg:

  my @restriction = @original.grep:{ $_.{'a'} eq 'foo' };

Suffice it to say that, along those lines, there are 4 terms.

The actual syntax of RM "restrict" is more like "grep" than the other 3.

But that doesn't have to matter for us. We don't have to use the same words as domain-specific languages to name an operation, but a name that works well in english is very helpful.

-- Darren Duncan

Reply via email to