Source filtering, the O'Caml way

robin on 2002-05-23T14:50:01

Recently I've been playing with O'Caml, which is a charming language.

It has a source filtering mechanism called camlp4. At the heart of it is an extensible replacement parser, which makes it almost trivial to change or extend the language. One of the examples in the manual adds a new loop construct in six lines of code.

Of course, camlp4 itself is written not in ordinary O'Caml but in the "revised" (formerly "righteous") syntax invented by the author of camlp4.

It's interesting that several of the "big" changes planned for Perl 6 are already features of O'Caml: extensible syntax, currying, stable multithreading.

Oh, and it's (conceivably) faster than C++.


macro languages

pflanze on 2004-08-31T13:57:27

(I've begun using lexical subs as well some time ago :-).)

Do you know Scheme? One interesting thing in Scheme is continuations, which Ocaml (to my knowledge) is lacking, but parrot is promising to deliver.

Scheme and Lisp in general are the prototype of extensible syntax languages. I haven't tried camlp4 yet, so dunno if it's going to be as clean.

There are quite fast (and some very fast) scheme implementations as well. One thing that might make Scheme more similar to Perl than Ocaml, is that it's (generally) dynamically typed - some say that's a good thing.

Currently I like the Scheme/Lisp syntax, it's clean, and it helps learning to think cleanly about all the zillion things one is doing with xml technologies - maybe it's even a fine implementation language for all of them.