[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: are dylan macros Turing-complete?



In article <1ycl87k9zc.church.of.emacs@localhost.verbum.private>,
 Colin Walters <walters@debian.org> wrote:

> Bruce Hoult <bruce@hoult.org> writes:
> 
> > Perhaps substitute "the majority of transformations that defmacro is 
> > commonly used for"?
> 
> Yes, that's what I meant.
> 
> > There are certainly useful things that you can't do wth Dylan macros, 
> > but perhaps they are uncommon in practice.
> 
> One cool thing that I've seen done with CL macros is mixing HTML with
> Lisp code.  For example, from examples/chat.cl in the allegroserve
> source code:
> 
> (defun quick-return-master (req ent)
>   ;; quick hack to get us to the master controller while debugging
>   (if* (null *master-controller*)
>      then (ancient-link-error req ent)
>      else (with-http-response (req ent)
> 	    (with-http-body (req ent)
> 	      (html 
> 	       (:html
> 		(:body "The master controllers is "
> 		       ((:a href 
> 			    (format nil "setup-chat?s=~a"
> 				    (secret-key *master-controller*)))
> 			"here"))))))))
> 
> I had one experience with programming PHP, and it left me with a very
> bad taste in my mouth.  Having a real macro system which allows one to
> embed languages (e.g. HTML) like this is a huge win, I think.
> 
> Can the Dylan macro system express something like this?  I can't see
> offhand how to implement it...

It depends what you want this to compile into.  If you want all the HTML 
elements to become static text then you're out of luck.  I can't see any 
reason, though, that you can't make a Dylan macro that accepts this sort 
of syntax and outputs a suitably nested list, or some code that builds a 
tree at runtime.  You'd then have a function that walked the tree to 
actually emit the HTML.

As far as Syntax goes, S-expressions are pretty much just a rational 
format for HTML (and XML) with less typing and redundancy anyway, so you 
might well want to keep that aspect.


If you want to see perhaps the best current example of what can be done 
with the Dylan macro system, see David Lichteblau implementation of the 
"META" parsing library.

-- Bruce