''[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, lex, yacc [http://dinosaur.compilertools.net/] * '''Mathematics:''' MATLAB (high-level language and interactive environment for computationally intensive tasks)[http://www.mathworks.com/products/matlab/] * '''systems-level bit-twiddling''' C * '''interacting with command-line programs''' expect * '''composing structured text''' [STX], [TIP] format, [wikit]'s page formatting language * all of the tcl [little language]s * [regexp] Controversial examples: * (''not usually thought of as a language'') '''network protocols''' for performing the network interaction specified by the protocol, so SMTP for example, can be considered a DSL for defining a mail exchange. If Java can use XML, we can use SMTP. * (''also not usually thought of as a language'') '''Undo Lists''' - programs which implement an ''undo'' function must do so by maintaining an ordered list of functions to apply to reverse a given operation - these have linguistic structure. 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 [http://www.martinfowler.com/bliki/DomainSpecificLanguage.html] [http://homepages.cwi.nl/~arie/papers/dslbib/] [http://compose.labri.fr/documentation/dsl/dsl_overview.php3]. Microsoft has its own visual-programming take on DSLs: [http://msdn.microsoft.com/vstudio/DSLTools/]. '''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. [218]: Interesting approach is described in this[http://arxiv.org/abs/cs.PL/0409016] article by V.S. Lugovsky. ---- Implementation of DSLs is sometimes effectively done as "[programming by exception]". ---- [AM] (3 march 2006) I consider the script in [Solving the advection-diffusion equation] an example of a domain-specific language: * The script defines some convenient commands to get the description of the physical-mathematical problem into the solver's data structures * It uses the control structures offered by Tcl to steer the computation and produce output. ---- [CMcC] (Wed 13th Sept 2006) tcl is eminently suitable as a target for compilation of DSLs, in that it has a very regular/minimal syntax and a rich and extensible semantics. Tcl's syntax supports trees (as lists of lists) and lexically ''colouring'' elements with semantics (by using [[]] instead of {} to delineate sub-tree nodes.) It is therefore possible, and quite often effective, to transform (compile) a DSL into tcl, then evaluate the product. This is how I implement [STX] ... parsing the input text into functional units, basically duples (function and text-or-subexpression) and then lexically converting these into invocations of tcl-supplied semantics. ---- [Category Glossary]