A little language
is a programming language designed to be very small and focussed on doing just
what the designers of it had in mind. The term comes from Little Languages
, Programming Pearls, Jon Benley, 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.DKF
: It is the Tcl experience that little languages tend to grow. After all, that's what Tcl started out as: a common little language for John Ousterhout
's EDA tools.
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 (twelve since version 8.5) 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
- pattern matching
- whose language is also used in if, for, and while selectors
- adds specialties like %W substitution, + command prefix, break outside loops
- bind sequences
- e.g. <Control-Button-1>
- format/scan/binary format/binary scan
- clock format
- command indices can be specified as end-1 or $var+1 or similar.
- includes syntax for redirection and variable substitution
- | is a special syntax at the beginning of a file name argument
- Variable names
- as seen in the first argument of set, and lots of other commands. (disputed)
- item ids.
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 language
: Some of these seem a little dubious to be called "languages". switch
takes a dictionary
of pattern-body pairs; how is this a new language? I'm also confused about the inclusion of string
- are all ensemble
s to be considered separate languages? The syntax for variables and namespaces used by set
and $, would also seem to be an essential part of the syntax of Tcl itself rather than being a separate little language. A syntax on its own doesn't make a language.Peter da Silva
: I don't think the lindex command index and other similar special cases really qualify as "languages" (and, really, some of them should be considered mistakes)AMG
, in a perverse mood: Maybe calling every command a separate "little language" is just a nice way of saying that their interfaces are inconsistent. Certainly I recognize that it's good we have little languages as opposed to the rigid structure imposed by a language like C
or (shudder) Java
, but that doesn't mean we should abuse this power to avoid worrying about making the standard library of commands self-consistent. (Yeah, yeah, I know the idiosyncrasies from command to command are usually driven by historical reasons, but I'm just trying to make a point.)
An alternative to little languages is sometimes to have a great many parameters for the programmer to set. Tcl/Tk features with that kind of interface include:
Some problems lend themselves towards one approach, some rather to the other. As a matter of Tcl Advocacy
it is however interesting to observe that most languages other than Tcl have a syntactical rigidity that makes it difficult to take the little language route.
Some little languages that are not part of the Tcl/Tk core are:
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
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.
See Also edit
- Little Languages, C2 wiki