red / REP

Red Enhancement Process
BSD 3-Clause "New" or "Revised" License
11 stars 4 forks source link

WISH: sorting records on multiple items #48

Open meijeru opened 5 years ago

meijeru commented 5 years ago

sort works on blocks representing "records" with the /skip refinement. It has a /compare refinement with an integer! argument which indicates the position of the component within the record, on which to sort. If one wants to sort on multiple components, in a hierarchical fashion, it would be good to have a block! argument to /compare with the positions of the components on which to sort, in the order of importance -- sort first on this component, and when they are equal, sort on that component, etc.

endo64 commented 5 years ago

What does current /compare with a block!?

meijeru commented 5 years ago

@endo64 It gives an error message, even though block! is in the typespec.

greggirwin commented 5 years ago

We can add "TBD" to the /compare doc string.

endo64 commented 5 years ago

sort/compare with block as a comparator doesn't work on R2 too, and no effect the result on R3, o I can't see the use.

greggirwin commented 5 years ago

Seems OK in R2 @endo64, but I'm a bit foggy right now.

>> n-blk: [1 2 3  3 2 1  2 3 2]
== [1 2 3   3 2 1   2 3 2]
>> sort/skip/compare n-blk 3 [3]
== [3 2 1   2 3 2   1 2 3]
>> sort/skip/compare n-blk 3 [2]
== [3 2 1   1 2 3   2 3 2]
>> sort/skip/compare n-blk 3 [2 3]
== [3 2 1   1 2 3   2 3 2]
>> sort/skip/compare/reverse n-blk 3 [2 3]
== [2 3 2   1 2 3   3 2 1]

>> n-blks: [[1 2 3][ 3 2 1][2 3 2]]
== [[1 2 3] [3 2 1] [2 3 2]]
>> sort/compare n-blks [3]
== [[3 2 1] [2 3 2] [1 2 3]]
>> sort/compare n-blks [2]
== [[3 2 1] [1 2 3] [2 3 2]]
>> sort/compare n-blks [2 3]
== [[3 2 1] [1 2 3] [2 3 2]]
>> sort/compare/reverse n-blks [2 3]
== [[2 3 2] [1 2 3] [3 2 1]]
meijeru commented 5 years ago

It does indeed work in R2, and is useful. I have several applications that use it.