Version 15 of little language

Updated 2006-09-23 01:41:14

The term, little language, comes from Jon Bentley's column in Communications of the ACM 29:8 (August 1986), pp. 711-721. He points out that much of what we do as programmers can be thought of as creating "little languages" that are suited to particular small tasks.

For a very good example see Solving cryptarithms, especially the examples at end! To prevent over-deep brace nesting, a custom language for such riddles is designed and put to fascinating use.

The Tcl language is itself "little:" its formal syntax is described completely in eleven short paragraphs on the Tcl manual page. Most of its power comes from the fact that it is easy to embed other little languages within it. Obvious examples include:

  • Regular expressions (regexp, regsub, and others).
  • glob-style pattern matching.
  • The switch command.
  • The string command.
  • The expr command (whose language is also used in if, for, while conditions).
  • The bind command adds specialties like %W substitution, + command prefix, break outside loops
  • The format/scan commands and their binary brethren.
  • clock format
  • lindex/lrange command indices - you can specify end-1 or (as of Tcl8.5) $var+1 or similar.
  • exec arguments permit redirection and variable substitution.
  • open file name argument treats leading | as special.
  • set interprets its first argument as a variable according to a little language for resolving namespaces and array elements. The $ operator in tcl's core language also implements a subset of this little language.

All of these are comparatively small and self-contained, and do not have far-ranging effects on the rest of the Tcl system. In this way, Tcl can be understood in pieces; it's not necessary to know the whole language in order to be able to program in it.

These can all be considered particular domain-specific languages.

Some little languages that are not part of the Tcl/Tk core are:

AM The term "little language" is also used in a book by Kernighan and Pike: The practice of programming. That is a book I quite enjoyed reading and it uses examples in Awk, C, C++, Java, Perl and Tcl.


Little Language

for other little languages.

This begs the question of what the semantics of tcl would be without any little languages, which implies being without any commands. To this end, tcl-null discusses tcl stripped of all commands, as a beautiful but useless language - the process of adding back a minimal subset of tcl built-in commands is launched as a game for the obsessive.

[ Category concept - Arts and Crafts of Tcl-Tk Programming ]