develooper Front page | perl.perl6.language | Postings from February 2004

Re: The Sort Problem: a definitive ruling

Thread Previous | Thread Next
From:
Uri Guttman
Date:
February 19, 2004 20:36
Subject:
Re: The Sort Problem: a definitive ruling
Message ID:
x7llmyl65f.fsf@mail.sysarch.com
>>>>> "JG" == Joe Gottman <jgottman@carolina.rr.com> writes:


  JG>    How do you decide whether a key-extractor block returns number?  Do you
  JG> look at the signature,  or do you simply evaluate the result of the
  JG> key-extractor for each element in the unsorted list?  For example, what is
  JG> the result of the following code?

  JG>       sort {$_.key} (1=> 'a', 10 => 'b', 2 =>'c');

  JG>    There is nothing in the signature of the key-extractor to suggest that
  JG> all the keys are numbers, but as it turns out they all are.  Will the sort
  JG> end up being numerical or alphabetic?

my take is that either <=> or cmp (my pref) would be the default
comparator. if you want to force one, you need to use prefix ~ or + or
int.

oh, another reason to make cmp the default is BACKWARDS COMPATIBILITY!
we have support now for the old simple @sorted = sort @unsorted syntax
so the cmp should still be the default.

hey, i am remembering p6 syntax now! but give me a week and i will
forget it again :)

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About