Opened 8 years ago

Closed 8 years ago

#1306 closed defect (invalid)

The body of a syntax definer should be allowed to be a macro call

Reported by: johnwcowan Owned by:
Priority: major Milestone: someday
Component: unknown Version: 4.11.0
Keywords: Cc:
Estimated difficulty:


Currently Chicken doesn't support things like this:

(define (baz) 32)

(define-syntax foo
  (syntax-rules ()
    ((foo) (syntax-rules () ((bar) (baz)))))))

(define-syntax quux (foo)) ; fails with "foo not defined"

On most Schemes that support macro varieties other than syntax-rules (and therefore extend R5RS in this situation), macro calls are expanded in this position, and (quux) evaluates to 32. However, on Chicken they aren't. They should be.

Change History (1)

comment:1 Changed 8 years ago by sjamaan

Resolution: invalid
Status: newclosed

I believe this to be incorrect: you are mixing phases. The definition of foo defines a macro that needs to be available when defining quux, which is syntax, so it needs to be defined in a higher/earlier phase (what's the correct term for this?) than quux.

This works when you wrap the definition of foo in a begin-for-syntax, or if you put it in a separate module and import it for syntax:

(define (baz) 32)

  (define-syntax foo
    (syntax-rules ()
      ((foo) (syntax-rules () ((bar) (baz)))))))

(define-syntax quux (foo))

(print (quux)) ; prints 32
Note: See TracTickets for help on using tickets.