Autrijus Tang
Fri, 18 Feb 2005 00:28:03 -0800
After getting Life and Mandel to run on Pugs yesterday (see http://svn.perl.org/perl6/pugs/trunk/examples/ ), today I've made this version of Quicksort to run:
use v6;
multi sub quicksort ( ) { () }
multi sub quicksort ( *$x, [EMAIL PROTECTED] ) {
my @pre = @xs.grep{ $_ < $x };
my @post = @xs.grep{ $_ >= $x };
(@pre.quicksort, $x, @post.quicksort);
}
(1, 5, 2, 4, 3).quicksort.say;
Note the use of @xs.grep{} above. Pugs currently has two multisub
named "grep":
* List as invocant, takes a Code arg
* Takes two args: Code and List
It sort of makes sense to me. Please correct me if it's wrong. :)
But anyway. The real problem is the multisub dispatcher initially
complained about the () signature, saying that it is "non-slurpy"
and may not take a list, even though the list eventually flattens
into an empty list; so I modified the definition to make () explicitly
slurpy.
However, that feels wrong, as I'd like to distinguish from a slurpy
nullnary (something that can take a list, as long as it's empty) and a
non-slurpy nullary (something that takes no arguments whatsoever).
I have been wondering whether something like
quicksort( *[] )
Can mean a slurpy nullnary, but I failed to find relevant text in
Synopses, so here I am. :-)
(PS. Yes, I understand that I can use array unpacking and have
quicksort always take a single array argument, but I'd still like to
inquire about slurpy nullary...)
Thanks,
/Autrijus/
pgpSNaj5Bacws.pgp
Description: PGP signature