[Purdue-pm] Perl 6
Mark Senn
mark at purdue.edu
Sat Jul 23 16:43:48 PDT 2016
If you've been putting off learning Perl 6 because it runs slow,
for the things I use it for it is getting faster most every month.
The rest of the message is excerpted from
https://developers.slashdot.org/story/16/07/14/1349207/the-slashdot-interview-with-larry-wall
Proud Rooster:
How can we get PERL into the browser?
Larry Wall [the creator of Perl]:
Our rakudo compiler for Perl 6 was designed to have multiple
backends. Currently we support both MoarVM and JVM, but others are
planned. In particular, a Javascript backend is already underway, and
has progressed to the stage of being bootstrapped in NQP (that is, "Not
Quite Perl", the restricted subset of Perl 6 that rakudo itself is
written in), so the JS backend is most of the way to being able to
compile and run the full rakudo compiler, and once it can do that, most
of the rest of Perl 6 is already written in Perl 6, so someday in the
not-so-distant future you'll be able to compile and run Perl 6 anywhere
you can run Javascript.
At some point, the Nativecall library will also be ported, which gives
full access to pretty much any C shared library, as well as embedded
Perl 5, Python, or what have you, as well as their associated
libraries. (Of course, sandboxing might get in the way of that in a
browser, not to mention you can't rely on what the user has or hasn't
installed on the client anyway.)
By the way, the MoarVM backend uses libuv, so our semantics should not
be very far from what Node.js supports.
Some example Perl 6 code from later in the article:
sub postfix:<!> ($n) { [*] 1..$n }
say 42!;
Even if you don't know the language, you can see that it's defining some
sort of postfix operator called "!", which if you're at all familiar
with math, will look like a factorial. The parameter in parens looks a
lot like a parameter in many other languages. But instead of an explicit
loop or recursive definition, we're doing something to what is obviously
a range from 1 to $n. The prefix [*] is apparently related to the * of
multiplication somehow, and maybe the [] are indicating some kind of
list processing, since other parts of the program might be composing
lists using []. Together with the ! hint, it's probably sufficient for
you to deduce that [*] is some kind of reduce-with-multiplication
operator (sometimes called a "fold" if you're coming at it from the
functional programming end of things).
So you try this snippet, and find it prints:
1405006117752879898543142606244511569936384000000000
which you immediately recognize as 42 factorial. :-)
You might also be delighted that, without any extra work on your part,
it didn't overflow your native integer type.
-mark
More information about the Purdue-pm
mailing list