On Thu, Feb 12, 2004 at 12:07:37PM +0100, Ph. Marek wrote:
: > ...
: > so here is a (very rough and probably broken) syntax idea building on
: > that:
: >
: > sort :key { :descend :string .foo('bar').substr( 10, 3) }
: >
: >      :key {          :int .foo('baz') }
: >      :key {          :float .foo('amount') } @unsorted ;
: I see a kind of problem here: If the parts of the key are not fixed length but 
: can vary you can put them in strings *only* after processing all and 
: verifying the needed length.

I think this is easily solved by sorting on a list of strings rather than a
single string.

: - generating keys on every list element
: - storing them into a array (array of array) and
: - after having processed all checking the length, and
: - now generate the to-be-sorted-strings 
: - sort
: 
: isn't the optimal way.
: BTW: this requires that *all* keys are generated.
: In cases like
: - by name,
: - by age,
: - by height,
: - by number of toes left,
: - and finally sort by the social security number

Not if you lazily add strings to the list of strings mentioned above.

: That is to say, I very much like the syntax you propose, but I'm not sure if 
: pre-generating *every* key-part is necessarily a speed-up.
: 
: If there are expensive calculations you can always cut them short be 
: pre-calculating them into a hash by object, and just query this in sort.

Another approach is to declare a function that "is cached", I suppose.

: Also I fear that the amount of memory necessary to sort an array of length N 
: is not N*2 (unsorted, sorted), but more like N*3 (unsorted, keys, sorted), 
: which could cause troubles on bigger arrays ....

We'll just use virtual memory.  :-)

Larry

Reply via email to