[pro] Lisp and DSLs

Ryan Davis ryan at acceleration.net
Wed Jul 20 14:11:42 UTC 2011


Not sure if I'd call it a "pearl", but here's one data point.  Hell, I'm
not even sure if this counts as a DSL or not, most of what I know of
DSLs comes from blog posts and ruby fanatics.

I had a legacy electronic voting system (IIS/VBscript/SQL Server) and
wrote some lisp to configure elections.  The lisp code output the T-SQL
needed to configure the election, and then the VBScript was driven from
that data.

Here's an abbreviated example:

(with-election ("3/29/2011 8:00PM" "3/31/2011 7:00PM" "Law")
    (with-position ("President" :types '("Law Undergrad"))
      (make-candidates "name 1" "name 2" "name 3"))      
    (make-referendum "Amendment 1" "<strong>Thing To Change</strong>
<p>HTML body for the voting UI</p>"))

The :types indicated who was eligible to vote for the position, and
there were some other options to those macros.  The with-* forms are
macros to setup the context, and the make-* functions generate the
appropriate SQL strings and write them to a stream (usually a file).

The macros in the sample do a few things:

   1. with-election: sets a dynamic variable in lisp for the stream all
      the SQL strings are written to in make-* functions, allowed easy
      testing of make-* functions via the REPL
   2. with-position: sets a variable in the T-SQL script used by INSERT
      statements produced by make-candidates.  This actually
      macroexpands to imperative code: (progn (make-position ...)
      (make-candidates ...)).  The macro usage is mostly to get
      indentation and visually group the relationships

So, not sure if I'd call this a pearl and it's arguably a DSL, but it's
sure a lot easier for me to use than direct T-SQL or the ridiculous
VBScript web interface.

Other things I've used that might fall into the DSL category:

    * cl-who http://weitz.de/cl-who/
    * cl-interpol http://weitz.de/cl-interpol/
    * clsql's SQL-READER syntax (http://clsql.b9.com/manual/ref-syntax.html)

HTH,

Ryan Davis
Acceleration.net
Director of Programming Services
2831 NW 41st street, suite B
Gainesville, FL 32606

Office: 352-335-6500 x 124
Fax: 352-335-6506


On 7/20/2011 9:32 AM, Didier Verna wrote:
>   Dear friends,
>
> I'm starting to write a chapter for an upcoming book on domain specific
> languages. The chapter is called (tentatively):
>
> Extensible languages -- blurring the distinction between DSLs and GPLs
>
> GPL meaning General Purpose Language in this context ;-)
>
>
> My intention is to demonstrate how the task of implementing a DSL is
> made easier when it boils down to an extension or subset of your
> original GPL (hence reusing its infrastructure), instead of being a
> totally different language, only written on top of the other.
>
> Obviously, I'm going to illustrate this with Common Lisp, and I intend
> to speak of dynamicity (not only dynamic typing, but in general all
> things that can be deferred to the run-time), introspection,
> intersession, structural or procedural reflexivity, meta-object
> protocols (not sure about this one), macro systems and JIT-compilation. 
> Also, more specifically to Lisp, reader macros (compiler macros maybe?),
> the condition system (and its ability to *not* unwind) and restarts.
>
>
> Right now, I would like to know if any of you have DSL "pearls", nice
> examples of DSLs that you have written in Lisp by using some of its
> features in a clever or elegant way. I would also gladly accept any
> point of view or comment on what's important to mention, in terms of
> design principle or anything else, things that I may have missed in the
> list above.
>
>
> Thank you very much in advance!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/pro/attachments/20110720/600677a6/attachment.html>


More information about the pro mailing list