Perl 6 makes all of Lisp’s mistakes, then sets itself on fire.

Posted by Elf Sternberg as Uncategorized

As most people know, I’m a Lisp fanboy. Which is somewhat surprising as I tend to think that it’s one of my weakest languages, and whenever I’m reminded that Common Lisp is a Lisp-2 I get the heebie-jeebies; I really like single namespace languages. (I tend not to think of C as a namespace language; it’s really just assembly language with a nice syntax, and C++ is C with a ridiculous preprocessor.)

One of lisp’s classic problems is that it’s utterly reprogrammable. With the exception of a scant handful of absolutely essential core syntax terms (classically: cons, car, cdr, cond, eq, atom?, lambda, set!, quote) everything in the Lisp language is accessible and re-definable by the programmer. With macros you can add syntax that re-writes, mangles, and just plain defies scope and closure, that reifies complex procedures into one-word functions, and just plain lets you make one language into a different language. Lisp would be cool, except every Lisper’s Lisp is a little bit different from every other Lisper’s Lisp. It’s like the C++ problem of generics versus templates versus the STL. C++ has those problems because each of those topics is so huge someone who’s mastered one has little mental bandwidth left to master the others; in Lisp, those kinds of issues arrive because the developer wants them to.

So imagine my horror when I discovered that Perl 6 not only has the same capability, but allows you to define these new operators in any position in the syntax. Just look at this example:
sub infix:<¯\(°_o)/¯> { ($^a, $^b).pick }
say 'Coke' ¯\(°_o)/¯ 'Pepsi';

See that ‘infix’ thing there? That tells the Perl parser that you’re about to define a new kind of syntax. Your choices are: infix, prefix, postfix, circumfix, and postcircumfix. If your use case mixes your syntax with other syntax and the precedence isn’t correct, you add “is looser than” or “is tighter than (other syntax)” to the subroutine’s interface definition!

I loved Perl 4. Perl 4 put food on my family for six solid years. Perl 5 seemed like a pretty good idea until Moose and Catalyst made it feel like Haskell without the safety rails. I like Lisp, and if you can tinker with advanced grammars at least you know there’s only one canonical function position and absolutely no precedence wrangling needed at all.

There’s an old joke that Perl is a write-only language; six months after writing it, even the original developer has little idea how to understand what he wrote. With the capability to arbitrarily re-define precedence order, syntax positioning, and even Perl’s basic grammar for your precious, delicate snowflake of a use-case, it seems that Perl 6 really intends to make that ancient joke a reality.

4 Responses to Perl 6 makes all of Lisp’s mistakes, then sets itself on fire.

Matt Oates

April 8th, 2016 at 12:19 am

Anything can be abused but I like that there is a clean and correct mechanism for extending Perl 6 the core language syntax. It means new bits of the language can be experimented on in user modules and integrated with the core if they become important like Moose in Perl 5.

I’ve been working on my own slang of Perl 6 specific to bioinformatics:


It adds a quoted “ literal for biopolymer sequences. It goes a step further and actually defines additional grammar bits to the parser and and actions to output to the AST for handling this syntax. You can mixin your grammar into the actual compiler directly and safely.

The advantage of this is my syntax works really nicely with the built in REPL. Its a snowflake like use case, but makes the language REPL more like a bioinformatics shell and is implemented nicely. Thats a genuine use case of Perl 6 for me. Producing domain specific languages built on a language which already near enough has everything you want.

Arthur T. Murray

April 8th, 2016 at 5:54 am

https://www.reddit.com/r/perl6 sent me here to investigate what it means when Perl 6 “sets itself on fire.” Apparently it means that Perl 6 gives you too much freedom to do wild, unstructured things — tantamount to starting a fire. It is pleasing to see the Latin-based word “reifies” above in the statement that Lisp “reifies complex procedures into one-word functions.” Thank you for the interesting read.

Zoffix Znet

April 8th, 2016 at 6:31 am

Good point that with great power comes great responsibility. It’s true, you can make Perl 6 look completely different, especially if you add Slangs into the mix. But that’s for a programmer to decide and a competent one will consider all the drawbacks.

Keep in mind, custom operators are just subs, and thus are *lexically scoped.* You can define them anywhere you want, but you can use them only in the scope that sees that definition.

It’s fine to show my patented Shrug Operator (press Left/Right to navigate the linked slides, BTW) and ridicule it, but the real usecases aren’t insane curiosities: first, you have the scientific and mathematical symbols that can make scientific and mathematical programs look much closer to what they represent. The next example in my slides is ∑ for n-ary sum. But most common usecase will be extending existing operators to perform something reasonable on objects you create.

Lastly, since custom operators modify the parsing grammar, they have a hefty compilation speed penalty, which works rather well in discouraging spawning an orgy of custom operators.


April 13th, 2016 at 2:38 am

couldn’t agree with you more… perl{4,5} put food on the table for over a decade… but as soon as perl6 was announced, we knew perl was pretty much dead, as perl6 was going to take more than 10 years (and everyone knew that from the outset), but since it was announced that it was going to be worked on, no-one wanted to do new stuff in perl5… and perl6 is not “perl” as we know it at all.. it’s a completely new language that has pretty much nothing to do with perl5 (except that the first 4 letters are the same!), it’s not a new version, it’s a completely different beast… and that completes the confusion… perhaps the creators thought that the uptake will be more as people will want to “upgrade” their skills, but hey, something things just don’t stand the saying of “you can fake it till you make it”…

Comment Form

Subscribe to Feed



April 2016
« Mar   May »