[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua as a "domain specific language"?
- From: Thomas Wrensch <twrensch@...>
- Date: Fri, 10 Mar 2006 00:19:33 +0000 (UTC)
The preface to "Programming in Lua" states that "many people regard Lua not
as a language, but as a kit for building domain-specific languages". Fair
enough, but what does that mean in practice? What usage of Lua qualifies as
"domain specific language"? Does anyone have a concrete example of using Lua
for such purpose?
(Note: I did a talk on this subject at the Lua Workshop in 2005. You can
find a copy of the slides at
http://www1.pacific.edu/~twrensch/luatalk/Wrensch05.pdf)
A domain specific language (DSL) is a language designed to be useful for a
specific set of tasks with some domain. A good example is YACC for writing
parsers.
Characteristics of DSLs are that they draw primitive programming
terminology and structure from the domain for which they are designed.
Thus a language for handling student grading would use terminology like
"student", "class", and "assignment" used to identify operations or
structures that were built into the language. Because there's a strong
mapping between the domain and the language, a small amount of code can
often do a lot of work -- as long as you stay in the domain for which the
language was designed!
Lua is particularly well suited to declaritive DSLs as might be used for
configuration or describing structure. For example:
Student {"ff012", "Fred Flintstone", email="f_flintstone@pacific.edu"}
Could define a student whose id number is ff012 and whose name is
Fred Flintstone, and could include any number of additional optional
items such as the email address given in the example. Student is,
of course, a function that takes this information and does quite a bit
of setup work for the student, including setting up an account on the
course webpage, assiging a temporary password, etc.
I've also used Lua to build a very-high level modeling language for
object-oriented systems. This was a more traditional DSL for designers of
object-oriented software systems. Rather than using Lua's syntax directly
it implements a language parser in Lua.
Lua, along with Lisp, APL, and Smalltalk can be considered a Domain
Oriented Programming (DOP) language. That mostly means that it's really
good for building DSLs. (For more information check out Thomas and Barry's
paper at OOPSLA'03).
Hope that helps,
- Tom Wrensch