Perl 6 - significantly nearer, and Rakudo looks very good
Archive - Originally posted on "The Horse's Mouth" - 2010-12-02 07:52:53 - Graham Ellis
Christmas may have arrived early this year ... for this morning I downloaded Rakudo Star - the November 2010 release that's been out for about a week ... according to Github 200 people had got there before me, so perhaps I'm still a bit leading edge. The Rakudo team describe it as "a useful and usable distribution of Perl 6" ... I haven't thrown enough at it yet to be sure but first impressions are that their claims are valid.
Rakudo Star unpacked, and built easily from source on my Mac (MacBook Pro with Developer's Xcode, running OS X 10.6.4) ... in a nutshell:
cd /usr/local
sudo tar xf ~/Downloads/rakudo-star-2010.11.tar
sudo chown -R graham rakudo-star-2010.11
cd rakudo-star-2010.11/
perl Configure.pl --gen-parrot
make
make install
cd /usr/local
sudo ln -s /usr/local/rakudo-star-2010.11 perl6
and into my ~/.bash_profile file add
export PATH=/usr/local/perl6:$PATH
then (in a window that's freshly creates to check the new path ...)
wizard:dec10 graham$ perl6
> print "Hello World\n";
Hello World
> exit
wizard:dec10 graham$
(Goodness - it's nice to have the interactive shell come up like that)
Let's try a real (Perl 5) program and - yes - that's going to throw up the compatibility issues:
sub ladder {
$plen = sqrt($_[0] ** 2 + $_[1] ** 2);
}
print "Hello World\n";
$moat = ladder(5,12);
$building = ladder(3,4);
print "Ladder lengths needed are $moat and $building\n";
wizard:dec10 graham$ perl oldperl.pl
Hello World
Ladder lengths needed are 13 and 5
wizard:dec10 graham$
but
wizard:dec10 graham$ perl6 oldperl.pl
===SORRY!===
Symbol '$plen' not predeclared in ladder (oldperl.pl:3)
wizard:dec10 graham$
And - straight away - you see the first "fix" - variables are no longer default global, even without the "use strict;". Thank Goodness!
Let's rewrite that code, but pull in another of the Perl 6 new features - named parameters:
sub ladder($width, $height) {
my $plen;
$plen = sqrt($width ** 2 + $height ** 2);
}
print "Hello World\n";
my $moat = ladder(5,12);
my $building = ladder(3,4);
print "Ladder lengths needed are $moat and $building\n";
Of course, that fails with Perl 5:
wizard:dec10 graham$ perl newperl.pl
Malformed prototype for main::ladder: $width,$height at newperl.pl line 8.
wizard:dec10 graham$
but it runs sweetly on Rakudo Star:
wizard:dec10 graham$ perl6 newperl.pl
Hello World
Ladder lengths needed are 13 and 5
wizard:dec10 graham$
There's a second of the big potential criticisms of Perl 5 wiped out - Wow!
Now - you should NOT consider that Rakudo Star is Perl 6.0.0 or anything like that - there are still some features to be tested and implemented; they're listed in more detail at http://rakudo.org/announce/rakudo-star/2010.11, but it is an excellent step and something that's becoming very practical indeed to start using. And I have to say I have been very impressed this morning - it downloaded, unpacked, compiled, ran my little tests flawlessly.
The Mac I used is the presentation machine. So Perl 6 (Rakudo Star) will be available for use on forthcoming courses. That's not to say that we'll switch straight over - we will NOT - but we will be able to add flesh to an introductory talk about Perl 6 by running it, and we'll be able to delve in deeper as and if our delegates require / request us to do so.
I think I'm going to have a good Christmas this year (although I may be slightly inseparable from my keyboard) ... and I go forward with a new spring in my step; it now looks much more likely that Perl will still be one of our major training language even in 2020.
Now if you'll excuse me, I'm off to play with the samples, and write a lot more code of my own.
The 'story' behind this application / sample program is told [here] (and that also tells you why there's a picture of Edinburgh Castle illustrating the article)
The Perl 5 source of the example above is [here]
The Perl 6 source of the example above is [here]