guile-user
[Top][All Lists]
Advanced

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

Nested macros


From: Wolfgang Jährling
Subject: Nested macros
Date: Sat, 31 Aug 2002 01:11:41 +0200 (MEST)

Hi there!

I have a problem with nested macros.  The following code illustrates it:

  (use-modules (ice-9 syncase))

  (define-syntax inner
    (syntax-rules ()
      ((inner FOO)
       (FOO FOO FOO))))

  (define-syntax outer
    (syntax-rules ()
      ((outer (BAR1 BAR2 BAR3))
       (list BAR1 BAR2 BAR3))))

  (outer (inner 'baz))

I expected the last line to expand into

  (outer ('baz 'baz 'baz))

and from that into:

  (list 'baz 'baz 'baz)

This does not happen.  The outer macro is expanded first, which results
in "invalid syntax", as "outer" expects three expressions in the
perentheses, but there are only two.

I wanted to use this to define slots for GOOPS classes more conveniently
(avoiding redundancy etc.).  My actual code looks like this:

  (define-syntax initialized-slot
    (syntax-rules ()
      ((initialized-slot NAME INITVAL)
       (NAME #:init-value INITVAL
             #:init-keyword (symbol->keyword 'NAME)))))

  (define-class <runlevel-changes> (<runlevel>)
    (initialized-slot start-on-enter '())
    (initialized-slot stop-on-enter '())
    (initialized-slot start-on-leave '())
    (initialized-slot stop-on-leave '()))

Does anyone have an idea what I could do to reach my goal?

Cheers,
GNU/Wolfgang

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net





reply via email to

[Prev in Thread] Current Thread [Next in Thread]