domain-specific language

A domain-specific language, or dsl is a language purpose-built for a specific problem domain. Tcl is itself is purpose-built for creating domain-specific languages by extending an interpreter with domain-specific commands.

See Also

programming by exception
One way to end up with a DSL.
little language

Reading

A Programmable Programming Language , Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, Shriram Krishnamurthi, Eli Barzilay, Jay McCarthy, and Sam Tobin-Hochstadt, Communications of the ACM, March 2018, Vol. 61 No. 3, Pages 62-71
Written about Racket, but even more applicable to Tcl. In particular, Tcl excels at "turning extra-linguistic mechanisms into linguistic constructs". One outstanding example is data structures, which in Tcl are expressed as strings having a particular format.
Using a hierarchy of Domain Specific Languages in complex software systems design , V.S. Lugovsky, 2004-09-09
Redis and scripting , antirez ,2011-04-27
Where antirez mentions Tcl and states that he considers Redis to be a DSL.

Tcl Domain Specific Languages

A DSL to generate XSD files
Automates the larges part of creating an XSD.
fileutil::multip::op
A DSL for performing operations on groups of files.
Gregor: A DSL for building semester calendars
Solving the advection-diffusion equation
See below.
Tcl
Tcl itself is a DSL for creating DSLs.
TDL
A DSL for XML.
Unified Power Format
Although it bills itself as a format, it is actually Tcl DSL.

Description

A domain-specific language is a programming language designed explicitly to express activities in a certain domain, and either incidentally or purposefully limits itself to those expressions directly relevant to that domain.

Some examples:

  • Text processing: awk, sed, m4
  • Document preparation: LaTeX, roff
  • Development of domain-specific languages: Tcl
  • Page description: PostScript
  • Software development: make, Lex, Yacc
  • Mathematics: MATLAB , Scilab
  • systems-level bit-twiddling: C
  • interacting with command-line programs: Expect
  • composing structured text: STX, TIP format, wikit's page formatting language
  • pattern matching: regexp, fumagic
  • everything that seems to fall outside Tcl syntax: all of the Tcl little languages

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 [L1 ] [L2 ] [L3 ]. Microsoft has its own visual-programming take on DSLs: [L4 ].

Tcl itself was designed as a primordial domain-specific language, ready to be extended into any specific domain via the customization of available commands in a given Tcl interpreter. John Ousterhout had written several tools for IC design, each sporting its own domain-specific language, and wrote Tcl as a single reusable DSL to end this pattern of implementing an ad-hoc quirky command interface for each program.

One tool method of extending Tcl into some domain is to create a safe interpreter and populate it with an appropriate set of commands.

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.


AM 2006-03-03: 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 2006-09-13: 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.