Doing Nothing Better in Perl 5

chromatic on 2008-05-10T02:24:04

Perl 6 has three code placeholder operators, known affectionately as the "yada, yada, yada" operator (see List Prefix Precedence in Synopsis 3). It's a matter of (very sarcastic) public record how much I love writing, maintaining, and patching parsers, so I've just sent a very preliminary five-line patch to p5p to add support for ... to Perl 5.

--- perly.y~	2008-05-09 17:47:35.000000000 -0700
+++ perly.y	2008-05-09 17:47:41.000000000 -0700
@@ -1227,6 +1227,11 @@
 			}
 	|	WORD
 	|	listop
+	|	DOTDOT
+			{
+			  $$ = newUNOP(OP_DIE, 0,
+ 			 	newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")))
+			}
 	;
 
 /* "my" declarations, with optional attributes */

Apply this to recentish bleadperl sources, run perl regen_perly.pl, rebuild, and now you can run programs such as:

sub foo { ... }
foo();

And get an "Unimplemented at file line line." error message.

(Now everyone who complains that I don't code enough to match my talk, please punch yourself in the face.)


Hmm

tsee on 2008-05-10T08:26:35

Damn, you beat me to doing that. (That's good for my spare time!) I was expecting the ... part to be reasonably straightforward since it's reasonably similar to what the sub stub does already, but I've been putting this off because of ??? and !!!. But maybe I'm wrong and those just need something really similar?

P.S.: I have been enjoying your blog posts much more since you switched from discussion of stuff to discussion of code. Please keep going.

Re:Hmm

chromatic on 2008-05-10T17:29:24

??? and !!! are similar to each other, because they rewrite into the die opcode, and that can happen in the lexer. The only problem is, as Ben Morrow pointed out, the lexer can rewrite the ??? of ??? : 1 : 0;, which is a mistake. Of course, it's also a horrible bit of code, and it's fixable with ?? ? : 1 : 0.

DOTDOT?

jplindstrom on 2008-05-10T12:42:10

Shouldn't ... be DOTDOTDOT?

Re:DOTDOT?

chromatic on 2008-05-10T17:36:17

That patch was a quick hack, but the DOTDOT token in the lexer also handles .... I merely reused it.

My newer patches are much cleaner.

Ellipsis operator

laburu on 2008-05-11T05:22:52

I take it that using “ellipsis” to refer to this incipient operator is out of the question.

Re:Ellipsis operator

chromatic on 2008-05-11T17:10:16

You might have to wrestle Damian for the right to rename it.