On Mon, Dec 15, 2008 at 11:18:54PM -0500, Mark J. Reed wrote:
> On Mon, Dec 15, 2008 at 5:41 PM, Moritz Lenz <mor...@faui2k3.org> wrote:
> > I know at least of infix:<cmp>(Num $a, Num $b) (which does the same as
> > Perl 5's <=>) and infix:<cmp>(Pair $a, Pair $b) (which does $a.key cmp
> > $a.key || $a.value cmp $b.value), so numbers and pairs DWIM.
> Hm. Rakudo doesn't let me cmp pairs at all currently:
> > (a => 2) cmp (a => 10)
> Multiple Dispatch: No suitable candidate found for 'cmp', with signature
> > 'PP->I'
It does now:
> say (a => 2) cmp (a => 10);
S02:1600 somewhat implies that comparison of pairs is based on
keys by default, then on values if keys are equal. Rakudo
implements this behavior.
In particular, one can now quickly print out a hash sorted by key
using C<< .say for %hash.sort >>:
my %hash = <parrot speaks your language> Z 1..4;
.say for %hash.sort;