>>>>> "RA" == Russ Allbery <[EMAIL PROTECTED]> writes:

  RA> Uri Guttman <[EMAIL PROTECTED]> writes:
  >>>>>>> "SC" == Simon Cozens <[EMAIL PROTECTED]> writes:

  SC> No, it wouldn't, don't be silly. The ST can always be generalized to 

  SC> ST(data, func, compare) =

  SC> map { $_->[0] } sort { compare($a->[1], $b->[1]) } map { [$_, f($_)] } data
                                    ^^^^^^^   ^^^^^^^

  >> and i don't see multiple keys or sort order selection per key.

  RA> Then you need to look at f and compare a little closer, since it's in
  RA> there.

and there is only extracted key being compared to another at the same
level, not multiple key levels. think about sorting by state and THEN
town. you can't do that with $a and $b and one f(). so you need multiple
compare ops and multiple f()'s. the point is that you have to generate
the ladder compare code as well as the calls to your f()'s.

  RA> Without creating a function to extract the key, you can't sort in
  RA> Perl at all.  sort { $a <=> $b } contains two functions to extract
  RA> the keys.

huh? $a and $b are not functions but aliases the the current pair of
keys (at the primary key level). i don't seen any functions in what you
show there. you don't need a function or even an ST to sort complex
records. as other have stated here, the ST is useful to remove common
key extraction code from the compare callback.

  RA> Functions don't have to be complicated, you know.

but sorts can be very complex. i think we are having a 'key' meaning
overload. i am using it in form of 'state' being the first key and
'town' being the second when sorting street addresses. $a and $b are
both values from the same key, not the key itself. in the ST $a and $b
are refs to the generated anon arrays being compared. they are not the
keys values, which are in $a->[1], $a->[2], etc., with the original
record being in $a->[0].

uri

-- 
Uri Guttman  ---------  [EMAIL PROTECTED]  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com

Reply via email to