Post Reply 
the prime have other Hidden functions?
07-04-2015, 08:34 PM
Post: #6
RE: the prime have other Hidden functions?
(07-04-2015 04:52 PM)Tim Wessman Wrote:  
(07-04-2015 11:22 AM)BruceH Wrote:  The SORT command appears to have an undocumented "rotate left" capability. ;-)

Nice... issue raised.

Note that I've also raised up your problem of sorting one list based on another. I am thinking an expansion to the sort that allows specifying the element, maybe a function to do the sorting with, and ability to have optional "dependent" lists to sort using the same order might be nice enhancement...

Thanks Tim. So something like...

a) A simple option is to allow SORT to take a second list as a second parameter.

Given
Code:
name := { "Bird", "Jordan", "O'Neal" }
height := { 2.06, 1.98, 2.16 }

then SORT(name, height) would return names ordered by height. Conveniently this doesn't break any existing code as SORT currently only takes one parameter.

Dependent lists could be as simple as SORT(name, age, height) but the problem here is a conceptual one: what is the return value (as two lists are changing but only one can be returned)?

I think it will be fine just to do:
Code:
name := SORT(name, height);
age := SORT(age, height);
height := SORT(height);

b) A more powerful version, drawing on the ANSI C "qsort" approach, allows the user to specify a comparison function e.g.:
Code:
SORTB("compare(a,b)",  { {"Bird",2.06}, {"Jordan",1.98}, {"O'Neal",2.16} } )

EXPORT compare(a, b)
BEGIN
  IF a(2) = b(2) THEN RETURN 0;
  IF a(2) < b(2) THEN RETURN -1;
  RETURN 1;
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: the prime have other Hidden functions? - BruceH - 07-04-2015 08:34 PM



User(s) browsing this thread: 1 Guest(s)