O Javanese Navajo

TorgoX on 2006-05-30T00:11:55

Dear Log.

I managed a minor trick/victory/tricktory with Skreeth: since Skreeth files might/must be Lisp code prefaced by (or just plain interleaved with) the PostScript preamble that will interpret the Lisp, I want such files to be editable in both emacs's Lisp mode and emacs's PostScript mode. To get that to be not too insane, I came up with this bit of code that is valid PostScript as well as valid Lisp:

(;) pop /; {} def (
quote %) ; pop
;% An all-around comment
; 1 2 3 add add ===

Lisp (and thus the Lisp mode) just sees that as: (quote %), which is a useless/harmless expression (but, importantly for the editor's Lisp-mode, it is a valid balanced s-expression and thus doesn't throw off the indent level or anything, as a big block of normal inlined raw PS would). And PostScript (and PostScript-mode) sees this as creating and then discarding the string-literal ";" and then defining a ";" operator to be a no-op, then creating and discarding a string-literal "\nquote %", then a comment line (which happens to start with the no-op operator ";", and then finally a line with another no-op operator and then adding up 1 and 2 and 3 and displaying it.

This hurts my brain, but it will all be useful later, I think.

I wonder if there's a name for this sort of program -- i.e., a bit of source that parses validly one way in one language and parses validly another way in another language. A "Janus program" maybe? I've seen such things for nroff/C, Perl/.bat, etc.

In other news, my grand plan to do a bunch of work on Skreeth this past few weeks (notably the actual Lisp-parsing part of the system) has been a total wash, as the past month has been a continual pie-fight of distractions and minor annoying ailments.


"Polyglot"?

pne on 2006-05-30T07:26:05

I've heard them called "polyglots" (see e.g. http://en.wikipedia.org/wiki/Polyglot_(computing) or http://www.nyx.net/user/gthompso/poly/polyglot.htm).

Re:"Polyglot"?

TorgoX on 2006-05-30T11:07:29

YES! That's the term!

SWEET ZOMBIE JESUS!