[plt-scheme] Another macro venture

From: Blake McBride (blake at mcbride.name)
Date: Sat Sep 9 11:38:07 EDT 2006

Greetings,

I now embark on yet another macro venture.  I've already spent
an hour on it.  I know I can figure it out eventually, but I figured
it's easier to ask than spend the rest of my morning on this.

Semi-curiously, scheme functions evaluate their arguments but
set! and define don't evaluate their first arguments.  I understand
that it's convenient that they don't, but it is inconsistent.  One of
the main attractions of scheme is the fact that it treats (what other
languages think of) variables and functions consistently and
without requiring any extra syntax (like lisp).  set! and define
seem inconsistent.  Lisp set (not setq) is more generic and
valuable at times.

I know you need a macro system to create a lisp-like set in scheme.
It should work (for those unfamiliar with lisp set) like the following:

(define a 'b)
(set a 5)

now:

a -> b
b -> 5

Since set evaluated its first argument (which evaluates to b), it set b to 5.

I'm trying to create a scheme set macro which works the same using
define-syntax and syntax-case.  I presume syntax-rules cannot do this.

Again, all this is trivial to express in a lisp-like macro system and the
few capture situations are easy to avoid with a little care.

Your help is appreciated.

Blake McBride




Posted on the users mailing list.