|
|
|
|
|
by orblivion
4563 days ago
|
|
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. |
|
Lisp had a nice idiom that Randal Schwartz translated in to Perl 5 in 1994 which became known as the Schwartzian Transform: http://en.wikipedia.org/wiki/Schwartzian_Transform
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).