October 30, 2003

the whole shebang

Geoffrey Pullum, over at the collective linguistics blog Language Log, has an entry pondering the fact that you can write computer programs in one language (say Perl) that quote other programs written in a different language (say csh scripting) and run them. He even gives an example of a shell script that writes out a quoted C program to a file and then calls the C compiler to translate it into an executable program. He moves on to macaronic sentences in natural languages:

What I say is sauve qui peut, mon vieux!

It seems to me what you have in code switching examples like the sentence above is two grammars at work. One of the reasons that this sort of thing works so well with computer languages is that not only are the languages syntactically specified, but also their semantics. I'm not so sure that natural languages are based on rules in the formal language sense, but rather pattern recognition. And if you're interested in programming languages that lend themselves to meta-programming, you can spend some quality time looking at Lisp. Oh, and the #! at the beginning of a Unix script is called a shebang.

Posted by jim at October 30, 2003 08:00 AM | TrackBack
Comments

I just wrote a class-factory meta-program in python.
(It works! I no longer understand it!) Writing it in Lisp would almost certainly have sucked a whole lot less.

When one talks of programs that write programs, though, surely one is required by custom if not by law to mention quines?

((lambda (x)
(list x (list (quote quote) x)))
(quote (lambda (x)
(list x (list (quote quote) x)))))

Posted by: des on October 30, 2003 08:59 AM

Beautiful, Des, I'd forgotten about quines, or self-reproducing programs. I haven't written any Lisp in years, but I still remember it foundly: as old as Fortran but much more elegant. I still think that CLOS is the best OO system I've seen and used: gotta love that metaobject protocol.

Posted by: jim on October 30, 2003 09:41 AM
Post a comment