Newsgroups: perl.perl6.language
From: r...@rodadams.net (Rod Adams)
Date: Mon, 16 Feb 2004 13:46:24 -0600
Local: Mon, Feb 16 2004 2:46 pm
Subject: Re: The Sort Problem
Damian Conway wrote: For the record, I do a lot of statistical work. On the sorts where I > Uri persisted: > > but int is needed otherwise? int is more commonly a sort key than > float. > > it just feels asymetrical with one having a symbol and the other a > named > > operator. > Sorry, but that's the way the language works. The more general and usual care about speed, I'm using floats far more often than ints. Uri's usage obviously varies from mine. Let's not hack up the language to make sort more efficient for some arguable benefit. I would entertain, however, C<float> and C<string> comparators (and > > DC> If you don't explicitly cast either way, C<sort> just DWIMs by When fed a number that it doesn't trust to be an int or a float, > > DC> looking at the actual type of the keys returned by the extractor. > > DC> If any of them isn't a number, it defaults to C<cmp>. > > that doesn't work for me. the GRT can't scan all keys before it decides > EXACTLY!!! So, if you want the GRT to kick in, you have to make sure the couldn't the GRT store the number with C<pack 'Nd', $_, $_>? (ok, there's some prepping for sign and endian, but you get the point) Seems like a not-terrible way to handle the issue. > Here's another example (all praise be to Rod!): Now that's just spiffy. Except in moving from my P5 version to your P6 > @teams = sort [ version, you have to s/?/??/ and s/:/::/, IIRC. > > DC> But you *can't* apply C<is descending> to a Code reference. I really don't see the problem with > > then how did you apply 'is insensitive'? > I applied it to the *block* (i.e. a closure definition). > > what i am saying is i think that you need to go back to the drawing > No, I think we have it...just put the appropriate trait on the extractor @out = sort {lc $_}, @in; It's short, simple, unambiguous, IMO very clean. But if people want to > > i just don't like the reverse args concept at all. it is not What my football example was meant to show is that no matter how much we > > semantically useful to sorting. sorts care about ascending and > > descending, not a vs b in args. > The problem is that sometimes comparator logic is suffiently complex that abuse poor C<sort> in the name of progress, we need to have a way to drop it all and go back to how we did it in P5, for those truly pathological cases where nothing else works. If people don't trust this, I'll come up with something worse. As a side note, the reason I couldn't find the original sort in question But in more common case, how much it break things to have type Comparator ::= Code(Any, Any) returns Int; become type Comparator ::= Code(Any, Any) returns Int where the '!' sets the reverse/descending trait? So we could get things like: @out = sort {!~ $_} @in; Overall, Damian's proposal looks very good. -- Rod Adams PS -- Only pure and utter insanity would lead someone to not make string You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||