RE: purge: opposite of grep

2002-12-09 Thread Brent Dax
It just occurred to me that Cpart is almost a specialization of Csort. Consider the results if you assign without binding: sub comparator { when /hi/ { 0 } when /lo/ { 1 } default { 2 } } @input = qw(high low hi

Re: 'hashkey context/Str context' (was Re: purge: opposite of grep)

2002-12-09 Thread Luke Palmer
Date: Sun, 8 Dec 2002 21:52:33 -0800 From: Dave Storrs [EMAIL PROTECTED] On Sat, Dec 07, 2002 at 01:28:41PM +1100, Damian Conway wrote: Dave Whipp wrote: I notice everyone still want Int context for eval of the block: Pease don't forget about hashes. Is there such a thing as

Re: purge: opposite of grep

2002-12-09 Thread Damian Conway
Smylers wrote: If the initial release of Perl 6 doesn't have commonly-required functions then people will write their own. People will do these in incompatible ways, ensuring that when it's determined that the language would benefit from having a particular function built in at least some

Re: purge: opposite of grep

2002-12-09 Thread Damian Conway
Ken Fox wrote: Sometimes array references behave as arrays, e.g. push $array, 1 In flattening context array refs don't flatten, only arrays. I'm not even sure that only arrays flatten either -- it might be anything that begins with @. e.g. my Point @p; ($x, $y) := @p; If the

Re: 'hashkey context/Str context' (was Re: purge: opposite of grep)

2002-12-09 Thread Damian Conway
Dave Storrs wrote: My understanding was that in Perl6, you could use pretty much anything for a hashkey--string, number, object, whatever, and that it did not get mashed down into a string. Did I have this wrong? Not wrong. But it's not the default. The default is Str keys only. But I take

Re: purge: opposite of grep

2002-12-09 Thread Damian Conway
Brent Dax wrote: It just occurred to me that Cpart is almost a specialization of Csort. Consider the results if you assign without binding: sub comparator { when /hi/ { 0 } when /lo/ { 1 } default { 2 } } @input = qw(high low hi lo glurgl); @out1 = part comparator @input; @out2

Re: purge: opposite of grep

2002-12-08 Thread Simon Cozens
[EMAIL PROTECTED] (Damian Conway) writes: Of course, as long as you can call Cpart without explicitly loading a module, it's merely a philosophical distinction as to whether Cpart is core or not. Well, no; it's an implementation distinction too. Non-core methods 1) don't mean anything

Re: purge: opposite of grep

2002-12-08 Thread Ian Remmler
On Sun, Dec 08, 2002 at 11:28:24AM +1100, Damian Conway wrote: We could certainly do that. But let's call it Cpart. I usually just lurk here, but I just had to pipe in. :) I'm not sure the meaning of the name Cpart would be obvious to someone who hadn't seen it before. I keep thinking Csift

Re: purge: opposite of grep

2002-12-08 Thread Ken Fox
Damian Conway wrote: sub part ($classifier, *@list) { return @parts; } Given the original example (@foo,@bar,@zap) := part [ /foo/, /bar/, /zap/ ] @source; this binds the contents of @parts to (@foo,@bar,@zap)? The array refs in @parts are not flattened though. Is it

Re: purge: opposite of grep

2002-12-08 Thread David Wheeler
On Saturday, December 7, 2002, at 10:47 PM, Damian Conway wrote: I keep thinking Csift would be nice, or maybe Cdiscrim. Just a thought... Csift is quite good. Though I still like Cpart best. Ooh, I like Csift best. Cpart is too easy to interpret as other things (partition? part with?

Re: purge: opposite of grep

2002-12-08 Thread Smylers
David Wheeler wrote: On Saturday, December 7, 2002, at 10:47 PM, Damian Conway wrote: Ian Remmler decloaked and wrote: I keep thinking Csift would be nice ... Csift is quite good. Though I still like Cpart best. Ooh, I like Csift best. I dislike Csift cos it's a small typo

Re: purge: opposite of grep

2002-12-08 Thread David Wheeler
On Sunday, December 8, 2002, at 10:20 AM, Smylers wrote: I dislike Csift cos it's a small typo away from Cshift. Yes, but I would expect to be a compile-time error, since the signatures are different. The same can't be said for r?index. David -- David Wheeler

Re: purge: opposite of grep

2002-12-08 Thread Damian Conway
Ken Fox asked: sub part ($classifier, *@list) { return @parts; } Given the original example (@foo,@bar,@zap) := part [ /foo/, /bar/, /zap/ ] @source; this binds the contents of @parts to (@foo,@bar,@zap)? Yes. The array refs in @parts are not flattened

Re: purge: opposite of grep

2002-12-07 Thread Michael Lazzaro
Damian Conway wrote: Michael Lazzaro wrote: How would you do something like: (@foo,@bar,@zap) := classify { /foo/ ;; /bar/ ;; /zap/ } @source; Since I don't understand what that's supposed to do, I probably *wouldn't* do something like it. What effect are you trying to achieve?

Re: purge: opposite of grep

2002-12-07 Thread Damian Conway
Michael Lazzaro wrote: (@foo,@bar,@zap) := classify { /foo/ ;; /bar/ ;; /zap/ } @source; A shorthand ... that classifies (or parts) @source according to the results of a series of tests, not just one. You mean, like: (@foo,@bar,@zap) := part { when /foo/ {0}; when /bar/ {1}; when

Re: purge: opposite of grep

2002-12-07 Thread Ken Fox
Michael Lazzaro wrote: (@foo,@bar,@zap) := classify { /foo/ ;; /bar/ ;; /zap/ } @source; A shorthand for: for @source { given { when /foo/ { push @foo, $_ } when /bar/ { push @bar, $_ } when /zap/ { push @zap, $_ } } } How about just

Re: purge: opposite of grep

2002-12-07 Thread Michael Lazzaro
Damian Conway wrote: or even a arrayed form, when the corresponding index was implicit: (@foo,@bar,@zap) := part [/foo/, /bar/, /zap/], @source; That's kinda nifty. But admittedly, it's not to-die-for necessary, if I'm the only one fond of it. Ken Fox wrote: and implement classify

Re: purge: opposite of grep

2002-12-07 Thread Tanton Gibbs
Damian Conway wrote: or even a arrayed form, when the corresponding index was implicit: (@foo,@bar,@zap) := part [/foo/, /bar/, /zap/], @source; That's kinda nifty. But admittedly, it's not to-die-for necessary, if I'm the only one fond of it. I think this makes a nice

Re: purge: opposite of grep

2002-12-07 Thread Damian Conway
Ken Fox asked: How about just (@foo,@bar,@zap) := classify [ rx/foo/, rx/bar/, rx/zap/ ] @source; and implement classify as a normal sub? We could certainly do that. But let's call it Cpart. Et voilĂ : sub part ($classifier, *@list) { my classify := convert_to_sub($classifier);

Re: purge: opposite of grep

2002-12-07 Thread Damian Conway
Damian Conway wrote: Et voilĂ : Or, of those who prefer their code sanely formatted: sub part ($classifier, *@list) { my classify := convert_to_sub($classifier); my @parts; for @list - $nextval { my $index = try{ classify($nextval) } // next;

Re: purge: opposite of grep

2002-12-07 Thread Simon Cozens
[EMAIL PROTECTED] (Damian Conway) writes: Why does everything have to be built into the first version of Perl 6? Everything doesn't. Everything shouldn't be. Just the really common, important stuff. I have to confess though, there are *many* times I've wished for this particular

Re: purge: opposite of grep

2002-12-07 Thread Me
push (/foo/ @foo || /bar/ @bar || /zap/ @zap), $_ for @source; Presumably, to avoid run time errors, that would need to be something like: push (/foo/ @foo || /bar/ @bar || /zap/ @zap || @void), $_ for @source; But perhaps... ( @foo,

Re: purge: opposite of grep

2002-12-07 Thread Damian Conway
Simon Cozens wrote: A categorise method would be just grand, and I think it should be shipped with the default Perl 6 array classes, but Perl 6 The Core Language wouldn't need to know about that particular method if it didn't want to. Err. Since arrays are core to Perl 6, how could their

Re: purge: opposite of grep

2002-12-07 Thread Damian Conway
ralph wrote: Presumably, to avoid run time errors, that would need to be something like: push (/foo/ @foo || /bar/ @bar || /zap/ @zap || @void), $_ for @source; True. Why not: part ( @source, /foo/ = @foo, /bar/ = @bar, /zap/ = @zap ); Because Cmap, Cgrep,

Re: purge: opposite of grep

2002-12-07 Thread Michael Lazzaro
Damian Conway wrote: (@foo,@bar,@zap) := part [/foo/, /bar/, /zap/], @source; If we're worried about the distance between the source and destination when there are many tests, maybe: part { /foo/ = @foo, /bar/ = @bar, /zap/ = @zap }, @source; Or, 'long' formatted: part {

Re: purge: opposite of grep

2002-12-07 Thread Damian Conway
Ian Remmler decloaked and wrote: I'm not sure the meaning of the name Cpart would be obvious to someone who hadn't seen it before. What, as opposed to Cgrep or Cmap or Csplice or Cqr or Cflock or Cref or Cfork or Cchomp or Ccrypt or Cgetservent or Cucfirst or Clstat or Cvec or...? ;-) I

Re: purge: opposite of grep

2002-12-06 Thread Miko O'Sullivan
On Fri, 6 Dec 2002, Damian Conway wrote: The selector block/closure would, naturally, be called in Cint context each time, so (again, as Larry pointed out) a boolean function would naturally classify into two arrays. Though it might at first be a little counterintuitive to have to write: OK,

Re: purge: opposite of grep

2002-12-06 Thread Graham Barr
On Fri, Dec 06, 2002 at 09:33:14AM -0500, Miko O'Sullivan wrote: For example, suppose I want to separate a list of people into people who have never donated money and those who have. Assuming that each person object has a donations property which is an array reference, I would want to

Re: purge: opposite of grep

2002-12-06 Thread Michael Lazzaro
On Thursday, December 5, 2002, at 07:55 PM, Damian Conway wrote: equally. The built-in would actually be doing classification of the elements of the list, so it ought to be called Cclassify. I worry that Cclassify sounds too much like something class-related, and would confuse people. What

Re: purge: opposite of grep

2002-12-06 Thread Tim Conrow
Michael Lazzaro wrote: I worry that C sounds too much like something class-related, and would confuse people. What about C or something? Decent thesaurus entries for include: assign, classify, comb, compartmentalize, discriminate, distribute, group, order, segregate, sift, winnow, amputate,

Re: purge: opposite of grep

2002-12-06 Thread Me
Michael said: I worry that Cclassify sounds too much like something class-related 'Classify' also seems wrong if some items are thrown away. I like 'part': (@foo,@bar) := part { ... } @source; Headed off in another direction, having a sub distribute its results like this reminds me of:

Re: purge: opposite of grep

2002-12-06 Thread Sean O'Rourke
On 5 Dec 2002, Rafael Garcia-Suarez wrote: John Williams wrote in perl.perl6.language : If you want good'ol Unix flavor, call it vrep. Compare the ed(1) / ex(1) / vi(1) commands (where 're' stands for regular expression, of course) : :g/re/p :v/re/p Or, to follow the spirit rather

Re: purge: opposite of grep

2002-12-06 Thread Sean O'Rourke
On Thu, 5 Dec 2002, Sean O'Rourke wrote: On 5 Dec 2002, Rafael Garcia-Suarez wrote: John Williams wrote in perl.perl6.language : If you want good'ol Unix flavor, call it vrep. Compare the ed(1) / ex(1) / vi(1) commands (where 're' stands for regular expression, of course) : :g/re/p

Re: purge: opposite of grep

2002-12-06 Thread Aaron Crane
Sean O'Rourke writes: On Thu, 5 Dec 2002, Sean O'Rourke wrote: how 'bout tang for Tog's A Negated Grep? Gah. s/Tog/Tang/. Wouldn't that mean we had to rename grep to 'gnat'? (Gnat's Not A Tang, presumably, never mind rot13 and reversal...) -- Aaron Crane * GBdirect Ltd.

Re: purge: opposite of grep

2002-12-06 Thread Damian Conway
Dave Whipp wrote: I notice everyone still want Int context for eval of the block: Pease don't forget about hashes. Is there such a thing as 'hashkey context'? I doubt it. Unless you count Str context. Perl6 is much better than Perl5 for naming parameters. Could we make the following work?

Re: purge: opposite of grep

2002-12-06 Thread Damian Conway
Michael Lazzaro wrote: How would you do something like: (@foo,@bar,@zap) := classify { /foo/ ;; /bar/ ;; /zap/ } @source; Since I don't understand what that's supposed to do, I probably *wouldn't* do something like it. What effect are you trying to achieve? Damian

RE: purge: opposite of grep

2002-12-06 Thread Brent Dax
Damian Conway: # Also, can I return superpositions (sorry, junctions), to provide # multiple classifications? Or would I return an array for that? # # A (dis)junction ought to work there. That sounds horribly scary... --Brent Dax [EMAIL PROTECTED] @roles=map {Parrot $_} qw(embedding regexen

Re: purge: opposite of grep

2002-12-05 Thread Simon Cozens
[EMAIL PROTECTED] (Miko O'Sullivan) writes: FWIW, I came up with purge because my first inclination was to spell grep backwards: perg. :-) For reference, Ruby uses .detect and .reject. -- 3rd Law of Computing: Anything that can go wr fortune: Segmentation violation -- Core dumped

Re: purge: opposite of grep

2002-12-05 Thread Michael Lazzaro
On Wednesday, December 4, 2002, at 09:11 PM, John Williams wrote: On Wed, 4 Dec 2002, Miko O'Sullivan wrote: FWIW, I came up with purge because my first inclination was to spell grep backwards: perg. :-) While purge is cute, it certainly is not obvious what it does. Of course neither is

Re: purge: opposite of grep

2002-12-05 Thread Adam D. Lopresto
I like it except for the name, which feels too active to me (ie, if I were to purge those elements from the array I'd expect the array to be altered, instead of returning a new array with only those elements). But I do like the idea. I think the name except would be pretty nice, though. Then

Re: purge: opposite of grep

2002-12-05 Thread Miko O'Sullivan
On Wed, 4 Dec 2002, John Williams wrote: While purge is cute, it certainly is not obvious what it does. Of course neither is grep unless you are an aging unix guru... How about something which is at least obvious to someone who knows what grep is, such as vgrep or grep:v? How about my

Re: purge: opposite of grep

2002-12-05 Thread Robert Spier
How about my original inclinaton: perg? It just screams out the opposite of grep. So it greps a list in reverse order? -R (who does not see any benefit of 'perg' over grep { ! code } )

Re: purge: opposite of grep

2002-12-05 Thread Miko O'Sullivan
On Thu, 5 Dec 2002, Robert Spier wrote: -R (who does not see any benefit of 'perg' over grep { ! code } ) My problem with grep { ! code } is the same problem I have with if (! expression): I've never developed a real trust in operator precedence. Even looking at your pseudocode example, I

Re: purge: opposite of grep

2002-12-05 Thread Larry Wall
On Thu, Dec 05, 2002 at 10:09:08AM -0800, Michael Lazzaro wrote: : What about divvy (or are we already using that for something else?) : : my(@a,@b) = divvy { ... } @c; Any such solution must use := rather than =. I'd go as far as to say that divvy should be illegal in a list context. Note

Re: purge: opposite of grep

2002-12-05 Thread Dave Whipp
Larry Wall [EMAIL PROTECTED] wrote: On Thu, Dec 05, 2002 at 10:09:08AM -0800, Michael Lazzaro wrote: : What about divvy (or are we already using that for something else?) : : my(@a,@b) = divvy { ... } @c; Any such solution must use := rather than =. I'd go as far as to say that divvy

RE: purge: opposite of grep

2002-12-05 Thread Fisher Mark
FWIW, I came up with purge because my first inclination was to spell grep backwards: perg. :-) I like purge, although except, exclude, and omit all have their charms. For partition function, I like divvy, carve, segment (in that order) and almost anything other than separate, which IIRC is

Re: purge: opposite of grep

2002-12-05 Thread Miko O'Sullivan
On Thu, 5 Dec 2002, Dave Whipp wrote: Only if we apply a bit of magic (2 is a true value). The rule might be: How about if we just have two different methods: one for boolean and one for multiple divvies: my(@true, @false) := @array.cull{/some test/}; my (@a, @b, @c) := @array.divvy{some

Re: purge: opposite of grep

2002-12-05 Thread Rafael Garcia-Suarez
John Williams wrote in perl.perl6.language : While purge is cute, it certainly is not obvious what it does. Of course neither is grep unless you are an aging unix guru... How about something which is at least obvious to someone who knows what grep is, such as vgrep or grep:v? If you want

Re: purge: opposite of grep

2002-12-05 Thread Dave Whipp
Miko O'Sullivan [EMAIL PROTECTED] wrote: On Thu, 5 Dec 2002, Dave Whipp wrote: Only if we apply a bit of magic (2 is a true value). The rule might be: How about if we just have two different methods: one for boolean and one for multiple divvies: my(@true, @false) := @array.cull{/some

Re: purge: opposite of grep

2002-12-05 Thread Miko O'Sullivan
On 5 Dec 2002, Rafael Garcia-Suarez wrote: If you want good'ol Unix flavor, call it vrep. Compare the ed(1) / ex(1) / vi(1) commands (where 're' stands for regular expression, of course) : :g/re/p :v/re/p I like it. Fits in with our Un*x heritage, and doesn't have any existing

Re: purge: opposite of grep

2002-12-05 Thread Austin Hastings
--- Dave Whipp [EMAIL PROTECTED] wrote: I think that ccull would be an abysmal name: that implies keep the false ones. I'm not sure that there is a synonym for boolean partition though. Perhaps we need some help from a linguist! ;) What's wrong with split()? split { f($_) }, $iterator

Re: purge: opposite of grep

2002-12-05 Thread Damian Conway
I would suggest that we could get away with a single n-ary built-in. And I would strongly suggest that Cdivvy isn't the right name for it, since, apart from being a ugly, slang word, divvy implies dividing up equally. The built-in would actually be doing classification of the elements of the

purge: opposite of grep

2002-12-04 Thread Miko O'Sullivan
SUMMARY Proposal for the purge command as the opposite of grep in the same way that unless is the opposite of if. DETAILS I've lately been going a lot of greps in which I want to keep all the elements in an array that do *not* match some rule. For example, suppose I have a list of members of a

RE: purge: opposite of grep

2002-12-04 Thread David Whipp
Miko O'Sullivan [mailto:[EMAIL PROTECTED]] wrote: SUMMARY Proposal for the purge command as the opposite of grep in the same way that unless is the opposite of if. I like it. But reading it reminded me of another common thing I do with grep: partitioning a list into equivalence classes.

Re: purge: opposite of grep

2002-12-04 Thread John Williams
On Wed, 4 Dec 2002, Miko O'Sullivan wrote: FWIW, I came up with purge because my first inclination was to spell grep backwards: perg. :-) While purge is cute, it certainly is not obvious what it does. Of course neither is grep unless you are an aging unix guru... How about something which