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

Re: are dylan macros Turing-complete?



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...

> I've started going through the newly-released online copy of _On
> Lisp_, noting what there can and can't be applied to Dylan.
> Unfortunately progress is slow, due to work commitments at the
> moment.

That's a great book.  He covers Lisp macros *extensively*.  I learned
a lot from it.

> My own philosophy on the use of macros is that they are not for
> doing computation, but merely for rearranging the surface syntax so
> that the programmer can write something in syntax convenient to
> their application domain, and that is transformed into concrete code
> that implements their abstraction.  If this process requires
> optimization then that should take place in the compiler proper.

I think we're continually discovering new uses for a macro system like
Lisp's.  I really do like Dylan's system though too; it is pretty easy
to work with, given that Dylan has a much more complex syntax than
Lisp.

> I find the ability for a single macro to expand into methods added to 
> any number of Generic Functions to be incredibly powerful.  

Definitely; I do think though that the abstraction gained by generic
functions/object orientation is generally orthogonal to the power
gained by a real macro system.  Thus it makes sense that combining
the two would be a win.