Log in

No account? Create an account
entries friends calendar profile Elf Sternberg's Pendorwright Projects Previous Previous Next Next
As most people know, I’m a Lisp fanboy. Which is somewhat… - Elf M. Sternberg

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 developers 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 comments or Leave a comment
bolindbergh From: bolindbergh Date: April 3rd, 2016 07:57 am (UTC) (Link)
s/Lisp 6/Perl 6/;
featheredfrog From: featheredfrog Date: April 3rd, 2016 09:43 am (UTC) (Link)
thought so
elfs From: elfs Date: April 3rd, 2016 03:27 pm (UTC) (Link)
Fixed, along with the weird double-spacing that comes from the forwarder. Thanks!
From: (Anonymous) Date: April 13th, 2016 05:38 am (UTC) (Link)

Favorite Language

My favourite computer language was, and remains, PL/1. This despite there remaining no opportunity to utilize at all any longer. I found it well structured and fully feature complete for its time -- the very opposite of the hot mess that was C at that time. Never have understood how it lost out to C so badly.

4 comments or Leave a comment