Showing posts with label Schwartz. Show all posts
Showing posts with label Schwartz. Show all posts

Thursday, April 30, 2009

Schwartzian Transform - Perl 5 vs. Perl 6

This isn't quite news, but it's a cool little bit of code anyway.

Perl 5:


@sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [$_, foo($_)] }
@unsorted;


Perl 6:


@sorted = @unsorted.sort: { .uc };


I'm willing to claim that Perl 6 makes this a bit more readable, in spite of the smoke, mirrors and curtains.

Read more about the Schwartzian Transform in Wikipedia.