@out <== sort key:ri($_->[2]), key:s($_->[4]) <== @in;
Basicly, you have a list of RE syntax like C<key> values, whilch take various modifiers to say how to play with that key, and then an expr on how to generate the key given element $_.
Possible modifiers: (verbose versions welcome) :r reverse/descending :n force numeric comparisons :s force string comparisons (default) :u unicode (implies :s) :i case insensitive (implies :s) :l localized collation order :x call custom compare sub (a la P5)
This allows:
@out = sort keys %hash; # everything gets defaulted
@out = sort key:x{myfunc($a) cmp myfunc($b)}(), @in; # handy for P5 migration, but not much else
@out = sort key(myfunc($_)), @in; # same as above, but much better.
@out = sort key(%lookup{$_->{remotekey}}), key:ir($_->{priority}), @in; # complex in P5, easy here.
Advantages: - Uses syntax idioms used elsewhere in P6. - Common cases are easy - Decent huffman coding.
Disadvantages:
- Do we really want things that look like REs that are not REs?
- If we do this, are we setting ourselves up to create other RE-like creatures for grep, for, etc, to the point
where people will start wanting to roll their own in modules?
Thoughts? -- Rod