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

Re: How many arguments to a macro transformer?

This page is part of the web mail archives of SRFI 72 from before July 7th, 2015. The new archives for SRFI 72 contain all messages, not just those from before July 7th, 2015.

On Sat, 23 Jul 2005, Keith Wright wrote:

Oops!  I said:

On the other hand, it seems more consistant if

 (define-syntax (swap! a b) <body)

were the same as

 (define-syntax swap! (lambda ( _ a b) <body> ))

which implies that swap! is right and the rest of
the program is wrong.

I just noticed that this is a change you made in
the last revision,

Yes, I indeed made the change so that the short form

  (define-syntax (swap! a b)

corresponds to the long form

  (define-syntax swap!
    (lambda (form)
      (let ((a (cadr  form))
            (b (caddr form)))

and /not/

  (define-syntax swap!
    (lambda (_ a b) ....

which I had before. While this latter (discarded) format would have been more brief for certain simple (especially lexical) macros, notice that it requires the input form to be a proper list and is therefore less general than the long form

  (define-syntax swap!
    (lambda (form)

which can accept dotted lists or (perhaps in future) even single identifiers.

The long form is now compatible with the SYNTAX-CASE system. However, the short form above is not. Indeed, I find the short form

  (define-syntax (swap! a b)

more useful than the relatively recently introduced SYNTAX-CASE one:

  (define-syntax (swap! form)

even though the latter would conform more to one's expectations from experience with DEFINE.