I envision a select, reject, and partition, where @a.partition($foo)
Returns the logical equivalent of [EMAIL PROTECTED]($foo), @a.select($foo)] But only executes $foo once per item. In fact. I'd expect partition to be the base op and select and reject to be defined as partition()[1] and partition()[0] respectively... On 9/19/06, Jonathan Lang <[EMAIL PROTECTED]> wrote:
Larry Wall wrote: > Mark J. Reed wrote: > : I have no horse in this race. My personal preference would be to > : leave grep as "grep". My second choice is "select", which to me is > : more descriptive than "filter"; it also readily suggests an antonym of > : "reject" to do a "grep -v" (cf. "if !" vs "unless"). But I'd accept > : "filter", too. Given a choice between 'grep', 'filter', and 'select/reject', I'd prefer the third model: it counterbalances the break from tradition with additional functionality. > But which *ect do we call the one that returns both? In short: if 'select/reject' would be analogous to 'if/unless', should 'select' be allowed the equivalent of an 'else' as well as a 'then'? Personally, I think that this would be an unneccessary complication - much like 'unless' doesn't get to split code into true and false branches, and statement modifiers can't be nested. Meanwhile, your examples seem to be illustrating another possibility: something analogous to 'grep' that uses the 'given/when' paradigm instead of the 'if/then' paradigm. This, I think, has promise - though, as you say, there's already a way to do this using gather. What I'd be looking for would be a more compact syntax: (@good, @bad, @ugly) = @stuff.divvy { when .sheep { @good } when .goat { @bad } default { @ugly } } ...or something of the sort. Regardless, this oughtn't actually be the replacement for grep, IMHO; it should _supplement_ grep instead. > Anyway, it's not clear to me that grep always has an exact opposite. I don't see why it ever wouldn't: you test each item in the list, and the item either passes or fails. 'select' would filter out the items that fail the test, while 'reject' would filter out the ones that pass it. -- Jonathan "Dataweaver" Lang
-- Mark J. Reed <[EMAIL PROTECTED]>