Skip to content

Instantly share code, notes, and snippets.

@japhb
Forked from jnthn/gist:221659
Created October 29, 2009 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save japhb/221787 to your computer and use it in GitHub Desktop.
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
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