I realize this is drifting off topic, and I could well believe the current Rakudo implementation doesn't actually save the memory (I could believe it does, I just don't know) but P6, for any method, including sort:
my $a = [2,1]; say $a.sort; say $a # 1 2 2 1
my $a = [2,1]; say $a.=sort; say $a # 1 2 1 2
This riffs off the general op= syntax:
my $a = 1; say $a + 1; say $a # 2 1
my $a = 1; say $a += 1; say $a # 2 2
Hmm? I thought the whole point of the article was "Most people know about sort(cmp=), which takes two parameters. But check out sort(key=), it only takes one parameter, which means the key function only has to run once per item", but for Perl.
It seems from the comments here that Python's key and cmp args are Python's equivalent to the ST. I'm surprised by the comment that Python 3 removed cmp. Perhaps that's a temporary omission.
This HN is about an advent article for Perl 6, which covers the same territory. Based on a look at the Rakudo code, it only implements a single custom sort closure (equivalent to Python's cmp) OR a single key closure (equivalent to Python's key).
> I'm surprised by the comment that Python 3 removed cmp. Perhaps that's a temporary omission.
Guido and company insist that you can (almost?) always find a way supplying a key function. For better or worse, they decided it was the best way, and going by the Python philosophy they removed anything that isn't the one obvious right way to do it. Perhaps it's available in a library somehow, that's what they did to other things that are unnecessary or useful 99% of the time but may still be 1% of the time.
Similarly, Guido once almost removed lambda, but he faced an insurrection.