[plt-scheme] Macro rule selection

From: Grant Rettke (grettke at acm.org)
Date: Fri Jan 30 17:07:21 EST 2009

Hi James,

I had replied off-list, but if it seemed worthwhile to include
everyone; then I am all for it too.

On Fri, Jan 30, 2009 at 3:44 PM, James Coglan <jcoglan at googlemail.com> wrote:
> I just started learning Scheme and am also trying to implement it,

In what language are you implementing it?

> so I'm just playing around with various features. I've been doing this for a couple
> weeks with SICP, haven't got to (apply). From what I gather, though, isn't
> (apply) just a way to call a function with arguments that are stored in a
> list?

Yes.

> It's not a syntax for variable assignment, so wouldn't do what my (!)
> and (square!) macros do. Is this correct? Or have I misunderstood what
> you're suggesting (this is quite likely)?

Sorry I didn't mean to be vague!

I like to look at how other people solve problems with macros and talk about it.

I took the implict contract here to be the fn will always be a
multiple-arity function; so you can leverage apply and it saves you
one rule.

The problem is that it diverges from your syntax; but another way to
look at it is it is one less shape to have to remember.

(define-syntax !
  (syntax-rules ()
    ((! x fn args ...)
     (set! x (apply fn x (list args ...))))))


Posted on the users mailing list.