-
-
Save japhb/221787 to your computer and use it in GitHub Desktop.
Working out a conjectured syntax for slicing long lists in a Perl 6 signature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
multi quicksort([$head, *@front, $mid, *@back, $tail]) { | |
my ($pivot, @others) := median-of-three($head, $mid, $tail); | |
my @rest := |@others, |@front, |@back; | |
quicksort(@rest.grep(* < $pivot)), | |
$pivot, | |
quicksort(@rest.grep(* >= $pivot)) | |
} | |
multi quicksort([$a, $b]) { $a < $b ?? $a, $b !! $b, $a } | |
multi quicksort(@a [$a?]) { @a } | |
my @x = 5, 8, 1, 9, -2, 3, 6; | |
say quicksort(@x).perl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment