>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:

>>>>> "Uri" == Uri Guttman <[EMAIL PROTECTED]> writes:
  Uri> i will let damian handle this one (if he sees it). but an idea would be
  Uri> to allow some form ofkey extraction via a closure with lazy evaluation
  Uri> of the secondary (and slower) key.

  RLS> I still don't see that.  I understand about the lazy key
  RLS> evaluation.  However, the sort block in Perl5 contains more than
  RLS> just two key computations: it also contains the logic to decide
  RLS> *how* to compare the keys, and *when* more information is needed
  RLS> (a secondary key step, for example).  Not sure how you're going
  RLS> to replace that with just information about how to compute "a
  RLS> key".  I think you've had your head inside GRT for too long. :)

because the key description also specifies the comparison style. and it
would even be possible to pass in a closure (with $^a and $^b) to do the
actual comparison which gets you the p5 sort style that way. the
determination if you need more info would normally be when the previous
key sorts the same and that can be handled. the only odd case is when
you have a very bizarre set of comparison rules where simple == and cmp
don't work for this data. then the custom compare closure can also be
used.

  RLS> So, for the simple case (string sort against some function of each item),
  RLS> I can see the need for a good shortcut.  However, the general case (let
  RLS> me tell you how to sort two items), you'll still need a very perl5-ish
  RLS> interface.

i don't see why you need that except for the odd cases. but as i said
supporting custom compares is fine and can be done in a p6 way with a
comparison closure. but even for simple sorting of two items, i would
prefer to use a key extraction as that means you don't have redundant
code and you describe the comparison as numeric or string which i think
it better than cmp or ==. and at least in sort::maker you don't need to
do more than say number or string which is simple enough.

uri

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

Reply via email to