Of course you can express any DSL in Lisp as well as in any other Turing complete language. The question is when it is easy and when not. It is easy to represent XML in Lisp because XML is nearly identical with a part of Lisp - the S-expressions. So every XML document is easily translated to a Lisp data structure with all of it's structure. But you cannot so easily translate the structure of an language that is a bit more than a Context Free Grammar.
By the way the usefull DSL would not be easily translated into the host language, because this makes the DSL a bit trivial. | [reply] |
Expressing DSLs in Lisp is quite different from doing so in other languages. In general you can't express DSLs in other languages in any useful sense (only by writing an interpreter in that language or writing a compiler to that language). In Lisp, though, using macros you can modify the language you are using, adapting it it to the problem domain.
This is easy to do and certainly not trivial (in terms of usefulness). For example, you might need a language for validating the structure of documents. DTDs are one example of these. In Lisp you can implement a series of macros so that you can express DTDs directly in Lisp (I've done this), then the DTD executes as a Lisp program. You just write DTDs using parenthesis instead of the usual syntax.
Or, consider something like YACC. YACC is a DSL for writing parsers. You could write a parser directly in C, but it would be very tedious. YACC programs (or specs or whatever they're called) are not C programs, though they get translated into C. In Lisp you could just extend the language to implement the semantics of YACC. You wouldn't need a separate YACC program.
Lisp is different.
As Guy Steele said: If you give a programmer FORTRAN, he has FORTRAN. If you give a programmer Lisp, he has any language he wants. Turing completeness isn't really the issue. Lisp is really convenient for implementing useful DSLs.
| [reply] |