What order does SORTED OF employ?

I’ve been trying to write code for merging data sets that were themselves pre-sorted in the same order, e.g. (1 2 5) with (3 4 6): both pre-sorted in ascending order; or (5 2 1) with (6 4 3): both descending. A general way to do this is to specify a key function k (x), and sort the items by their keys, using Streams library v2 wip script pic 39. Another, somewhat less convenient way is to compare items (or their keys) pair wise - the result should be the same..

… or so I thought. It turns out Snap! doesn’t consistently work like this:

In this example the key function k (x) = x, for simplicity. What strikes me is that 1 vs. 2 are sorted in ascending order (i.e, aligned with Streams library v2 wip script pic 40, whereas 1 vs. “a” isn’t. I’m asking: why, for Pete’s sake? And what order does sorted of employ?

The source code comment explains it all. For heterogeneous data, only type ordering is used.

// private - this is an elaborate version of reportBasicLessThan()
// that is similar to snapEquals in that it will work with heterogeneous
// data types but is too slow for everyday use. Therefore it is currently
// only used for the generalized sorting of arbitrary data (lists)
// and not exposed as the (better) semantics behind "<"
var order = [

OK … so, for the generalized case I’d better use Streams library v2 wip script pic 42, then? Tried that; it works for me!

Please note (@bh, @jens) this (mis)feature is not documented for users: online help, manual - I, for one, don’t want to have to deep-dive into the source code to discover a block’s functional behaviour.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.