July 21, 2005
Lisp To Dylan

The John Wiseman of a year or two ago was on his way to posting something about Peter Norvig's Common Lisp-To-Dylan converter tool when, I assume, something came along and distracted me, since I don't see that post anywhere.

...here I produce Dylan code with nice indentation, to any specified column width, just by converting Lisp to a parse-tree syntax that is equivalent to Dylan, and then writing pretty-print directives for the parse-trees.

The one time I played with Dylan I was so put off by the terrible, terrible performance of the Harlequin Dylan environment that I had to stop after half an hour. But this code of Norvig's is still kind of neat.

LTD works by first reading a Lisp s-expression with ltd-read, then converting it to an internal s-expression representation which represents a Dylan parse tree with cvt-exp, and then printing the internal representation with dpp-exp (DPP stands for Dylan Pretty-Print). For example, calling ltd-read on the fragment of source file

;; Compute sign of x
(cond ((< x 0) -1)
      ((> x 0) 1)
      (t 0))

results in the expression

#S(com :comment " Compute sign of x"
       :code (cond ((< x 0) -1)
                   ((> x 0) 1)
                   (t 0)))

which gets translated by cvt-exp to the internal form

#S(com :comment " Compute sign of x"
       :code (IF (< X 0) -1 (:ELSIF (> X 0) 1) (:ELSE 0)))

which then gets printed by dpp-exp as something like

// Compute sign of x
if (x < 0) -1; elsif (x > 0) 1; else  0; end
Posted by jjwiseman at July 21, 2005 08:28 AM

Just thought that could be interesting...
I'm experimenting with using an approach similiar
to DPP to generate C#/VB.NET code from s-expr
based AST. The idea came to me after looking
at DPP code and some Dick Waters' examples
which show how to tune XP pretty-printer to
print Pascal from (quasi-)Lisp code.
This way one can use something like
Lisp macros to generate code in these [stupid]
languages. That can be useful for many LISPers who
want to add some automation to their non-Lisp job.

Here's some colorized sample code (rather simple
I wrote as a demo for one Russian .NET-oriented forum:


Non-colorized source is here:

Posted by: Ivan Shvedunov on July 21, 2005 01:59 PM

(sorry for duplicate comment)

Forgot about the demo output... It's here:

The text of message is in Russian (don't have time to translate it now),
but REPL sessions and code fragments are quite visible.

Posted by: Ivan Shvedunov on July 21, 2005 02:10 PM
Post a comment

Email Address:


Unless you answer this question, your comment will be classified as spam and will not be posted.
(I'll give you a hint: the answer is “lisp”.)


Remember info?