Version 20 of little language

Updated 2008-02-22 14:31:43 by avl

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 (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).
  • glob-style pattern matching.
  • The switch command. (disputed)
  • The string command. (disputed)
  • 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
  • bind sequences, like <Control-Button-1>.
  • 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.
  • Variable names (as seen in the first argument of set, and lots of other commands). (disputed)
  • canvas 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 languages.

NEM: 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 ensembles 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.

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) Peter da Silva

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:


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.


See

Little Language http://c2.com/cgi/wiki?LittleLanguage

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 ]