[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.



I got the new version 1.9, merged it with the changes I had
made, and tried the result on the old test cases.  I noticed
that the old test sequence started with the definition of
|swap!| and then went on to

  ;; This macro may also be expressed as:
  
  (define-syntax swap!
    (lambda (form)
      (let ((a (cadr  form))
            (b (caddr form)))
        `(,(syntax let) ((,(syntax temp) ,a))
          (,(syntax set!) ,a ,b)
          (,(syntax set!) ,b ,(syntax temp))))))

This second form has been removed from the new test sequence.
Indeed, it does not seem to work anymore.  Is it broken on
purpose, or have I got something screwed up again?

The main thing that attracted me to this SRFI in the first
place is that it seemed to make identifiers into just another
data type that can be put into an S-expression and manipulated
like any other.  So something very like this _should_ work.

> From: Andre van Tonder <andre@xxxxxxxxxxxxxxxxxxx>
> 
> Keith Wright wrote:
> 
KW > The short form is wonderful; we should keep it just as it is.
KW > 
KW > (2) It is a long tradition that a macro has one argument which is
KW > bound to the entire form of the macro call.  I think that both
KW > LISP 1.5 and Common Lisp do it that way.
>  
>  Thank you - more good reasons supporting the current choice.  

I looked it up in the Common Lisp manual before I made that
claim, so that part is right.  For Lisp 1.5 I relied on memory
and the more I thought about it the foggier the memory became.

Lisp 1.5 did not really have macros, and I am not really sure
any more how the FEXPRs worked.  But the tradition of one
argument macros goes back at least to Maclisp, I am pretty sure.

KW > The appendix of R4RS says that it has been suggested (it doesn't
KW > say by whom) that #'<datum> and #`<datum> would be felicitous
KW > abbreviations for (syntax <datum>) and (quasisyntax <datum>).
KW > Could this be added to the SRFI?
>  
>  I will add that as a recommendation in the next revision.

Did that happen?  I don't see it.

KW > As a stylistic matter, I think it would be better to remove uses
KW > of |syntax-case| and |with-syntax| from the examples, except
KW > where comparison with |syntax-case| is the point of the example.
>
>  Since |syntax-case| is included in the new revision, it is probably
>  okay to use it in examples where the pattern matching makes things
>  clearer.  Where it doesn't, as in the |syntax-quote| example you
>  raise, I'll work on rewriting them.
>  
>  By the way, my justification for including the |syntax-case| form, even 
>  though it is not a primitive, has not been well documented yet.  
>  So here goes:  
>  
>    * I am specifying an improvement in the semantics of syntax-case
>      for better hygiene.

That's good (I think).  So when you are discussing that improvement
you certainly need to put what you are discussing into the examples.

>    * A proposal that does not come with some form of pattern matching 
>      won't be regarded as usable by many Schemers.  

They will certainly demand that you _can_ implement pattern matching
in your system, but if your system does no more than provide an
implementation of syntax-case then they are likely to stay with
their own implementation.  In order to understand and love
the proposal it would be good to have as many examples as
possible of the new stuff.

>    * For R5RS compatibility, we need to provide syntax-rules.  

Again, we need to be able to implement it, but we don't need
to explain it, so it's better if the examples stand on their own.
Show that you can implement syntax-case and syntax-rules, but
then show off what you can do without them.

By the way, the changes I have made to your code are to
make a version of simple-macros.scm with the modules
ripped out.  This is not because I think modules are a bad
idea, I am just trying to understand macros by boiling
the implementation down to its bare core.  So I need test
cases that use only the core constructs.

KW > The link to Andrew Wright's pattern matcher
KW >  http://download.plt-scheme.org/.../match.ss
KW > at the end of kffd-match-tut.htm seems to be broken.
>  
>  Thank you - I removed it.  

Is it still available anywhere else?  I would like to know
what you had to change to adapt the run-time pattern matcher to
work with macros.  Is there any reason that there could not
be one matcher for both purposes?  That should be another
SRFI maybe.

-- 
     -- Keith Wright

Programmer in Chief, Free Computer Shop
 ---  Food, Shelter, Source code.  ---