Nathan <
nbee...@gmail.com> writes:
> I've been playing with Racket more lately and I'm struggling with
> macros.
The Racket mailing list is a much better place for such questions:
http://racket-lang.org/community.html (note that we also have gmane
mirrors of our mailing lists so you can use it as a newsgroup if you
prefer).
> define-syntax-rule is simple and beautiful compared to defmacro, but
> I'm struggling to get more advanced functionality out of it.
You shouldn't confuse the two. `define-syntax-rule' is just a quick
shorthand for `syntax-rules', which means that it's just as limited in
what it can do. `defmacro' is on a much higher level since it can run
any code at macro expansion time. (But of course it's broken wrt
hygiene, so you're probably comparing the two only on the merit of the
former's pattern-template rewrites vs the latter's use of
quasiquoting.)
> I'd like to be able to write recursive macros, but I keep ending up
> with weird errors.
The general rule with recursive macros (in any form) is that if a
macro expands into a use of itself, then that use should be smaller.
This is very obviously broken in this macro:
(define-syntax-rule (while cond body ...)
(when cond (while cond body ...)))
which is a mistake that macro newbies often fall into.
> I've got a macro here I've been using to write functions in the way
> I want to be able to define macros themselves, is this sort of thing
> possible for macro definitions or do I really need to just knuckle
> down to the more barbaric macro forms?
It will be more complicated (since in Racket all inputs will be syntax
vcalues), and probably way less useful (since it's rare for a macro to
dispatch on the kind of literal expressions provided to it).
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!