Version 3 of domain-specific language

Updated 2006-03-02 16:00:22

lexfiend 2 Mar 2006: A domain-specific language is, generally speaking, a language purpose-built for a specific problem domain. Some examples:

  • Text processing: awk, sed, m4
  • Document preparation: LaTeX, roff
  • Page description: PostScript
  • Software development: make, lexx, yacc

Aside from the concept of domain suitability alluded to above, many have tried to further pin down the defining characteristics of a DSL. For instance, see [L1 ] [L2 ] [L3 ]. Microsoft has its own visual-programming take on DSLs: [L4 ].

So is Tcl a DSL?

Well, no, not in the strict sense of the term. However, Tcl is one of those rare languages in which it's easy to create a proper DSL (i.e. one that minimizes/eliminates everything except the features specific to the domain) while still retaining the full power and expressivity of the base language for the DSL implementation itself. The secret sauce is, of course, safe or [interp create -safe].

NEM: Some people make the distinction between an embedded DSL and other forms of DSL. An embedded DSL extends some host language to add constructs relevant to some domain. In this case you have the full power of the host language available as well as the domain-specific features. Tcl lends itself well to this sort of DSL (regexp and expr are two examples). Lisp is another language good for EDSL development. The other choice is to make the DSL standalone, typically by writing an interpreter or compiler for it. In Tcl you can do that, as lexfiend says, by making use of interp and removing (or hiding) those commands that aren't needed and adding back in domain-specific ones. Another approach, popular in Java land, is to use XML to define a the syntax of a DSL. Visual DSLs are periodically trendy.

[programming by exception - lexfiend: what does it have to do with DSLs?]