Summary

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

Metadata

Description

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.

Changes and comments

[2016-07-17 13:06:38 UTC] sjamaan changed status from new to closed

[2016-07-17 13:06:38 UTC] sjamaan set resolution to invalid

[2016-07-17 13:06:38 UTC] sjamaan wrote:

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:

 #!scm
 (define (baz) 32)
 
 (begin-for-syntax
   (define-syntax foo
     (syntax-rules ()
       ((foo) (syntax-rules () ((bar) (baz)))))))
 
 (define-syntax quux (foo))
 
 (print (quux)) ; prints 32