[mercury-users] lisp macros
Richard A. O'Keefe
ok at cs.otago.ac.nz
Mon May 27 07:47:53 AEST 2002
I wrote:
> (defmacro x-define (Id . Body)
> `(define (,Id Element Ancestors) ,(list 'quasiquote Body)))
> (defmacro apply-templates ()
> `(process-children Element Ancestors))
Michael Day <mikeday at bigpond.net.au> replied:
Any tips on how this kind of thing would look in Mercury for
people who don't know lisp? :)
Different.
It isn't really relevant, because the point was what macros can do for
you. They can hide "plumbing"; they can define new binding forms (like
with-open-file, for example); they can make your code a lot shorter.
But for an example of the *kind* of thing that might be done this way,
consider Definite Clause Grammar rules, which are precisely the kind of
"hide the plumbing" technique I was describing. Come to think of it,
the functional sublanguage is also an example. (I and many other people
have term_expansion/2-based plugins that let you use functional syntax
in Prolog.)
The key reasons that macros for Mercury would look different are
- Mercury already has unification-based pattern-matching;
- Lisp and Scheme are imperative/functional hybrids; they can easily
have macros that introduce mutable variables without requiring them
to be coupled to an IO state, World, or IO monad.
- Lisp and Scheme have run-time types; they don't have to couple macro
expansions to a type environment.
What would Mercuy with macros look like then?
Shorter.
I'm sorry to say this, but after Haskell, Mercury is just so overwhelmingly
BULKY. (Even while I was working at Quintus, I had the same feeling about
Prolog.) Part of the reason is that Prolog syntax is pretty heavy on
punctuation marks, nearly as heavy as C and Java. Part of the reason is
that you can't hide the plumbing. Take a look at HaXML (which uses
combinators, not macros). What would that look like in Mercury? Bigger.
Different applications will have different plumbing to hide.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list