Macros defining macros with define-syntax 
Author Message
 Macros defining macros with define-syntax

I am having trouble understanding how define-syntax macros work. To
make Christian Quiennec's Meroon OO system[1] work with Scheme 48, I
would like to be able to write a macro which itself defines a macro.
For a traditional defmacro system such as Elk, the code is very
simple:

   (define-macro (define-meroon-macro call . body)
     `(define-macro ,call . ,body) )

   (define-macro (define-internal-meroon-macro call . body)
     `(define-macro ,call . ,body) )      

How to do something equivalent with define-syntax?

[1] http://www.*-*-*.com/ ~queinnec/WWW/Meroon.html

--
Eric Marsden

It's elephants all the way down



Tue, 16 Jan 2001 03:00:00 GMT  
 Macros defining macros with define-syntax

Quote:


>    (define-macro (define-meroon-macro call . body)
>      `(define-macro ,call . ,body) )

>    (define-macro (define-internal-meroon-macro call . body)
>      `(define-macro ,call . ,body) )      

I think this does the trick :

(define-syntax while
  (syntax-rules()
   ((define-meroon-macro call body1 ...)  ;; pattern match
    (define-macro call body1 ...)))       ;; rewrite rule

I think define-syntax macros are way-cool...

--

Brian Denheyer



Tue, 16 Jan 2001 03:00:00 GMT  
 Macros defining macros with define-syntax
For example...  I find myself typing a lot of "if" expressions which have no
alternate clause, ie, no else clause.  So, I choose to define a "when" macro
so I can write things like:

    (when (under-attack)
      (launch-missiles)
      (launch-anti-missile-missiles)
      (fire-star-wars-defensive-weapons))

I can achieve this with:

    (define-syntax when
      (syntax-rules () ;; This is frequently empty
        ;; There is frequently only one rule
        ((when condition . body)          ;; Before
         (if condition (begin . body))))) ;; After

It dawns on me that most of the macros I write have this format; no symbols
(ie, the () in the syntax rules is always empty) and one rule.  I decide that
it would be nice to be able to write:

    (define-simple-syntax (when condition . body) ;; Before
      (if condition (begin . body)))              ;; After

I can achieve this by writing a macro which expands to a macro definition,
such as:

    (define-syntax define-simple-syntax
      (syntax-rules ()
        ((define-simple-syntax (name . head) ;; Before
           body)                             ;; Before
         (define-syntax name                 ;; After
           (syntax-rules ()                  ;; After
             ((name . head)                  ;; After
              body))))))                     ;; After

Now the "define-simple-syntax" definition of "when" will expand in the same way
as the "define-syntax" definition of "when" at top.




Wed, 17 Jan 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. define-macro -> define-syntax

2. define-macro vs define-syntax

3. Scheme macro source: define/keyed, for defining keyword-triggered arguments

4. Question about a macro-defining macro

5. Macro-Defining Macros

6. help sought for macro defining macro

7. Load-time problem with a macro that defines a macro

8. defmacro/define-macro using syntax-case

9. is define-syntax inside define-syntax OK?

10. shadows of define and define-syntax

11. define in define-syntax

12. syntax-rules macros with sub-macros

 

 
Powered by phpBB® Forum Software