-->

Can Perl 6 sort or compare based on collations?

2019-06-17 02:08发布

问题:

The cmp operator works on code numbers, or at least that's what I think it does because the docs aren't explicit on that and don't mention any localization stuff.

Can I make it sort by other collations? I know I tell sort how to compare, but I figure it must be in there already (somewhere).

回答1:

Collation is available as an experimental feature:

my @list = <a ö ä Ä o ø>;
say @list.sort;                     # (a o Ä ä ö ø)

use experimental :collation;
say @list.collate;                  # (a ä Ä o ö ø)
$*COLLATION.set(:tertiary(False));
say @list.collate;                  # (a Ä ä o ö ø)

Please give feedback on this feature to help it move out of the "experimental" state and be included in v6.d.