Comment 1 for bug 260143

On Aug 21, 2008, at 10:22 AM, leppie wrote:

> I am not sure what is the correct behaviour with the following
> snippet/execution:
>
> (library (foo)
> (export mycond3)
> (import (rnrs))
> (define-syntax mycond3
> (syntax-rules (else3) [(_ (else3 e)) e])))

mycond3 matches on something of the form (_ (id _)) where
id is free-identifier=? to else3 in (foo). Since else3 is
unbound in (foo), it would match any unbound identifier
whose name is else3.

> (import (foo))
>
> (mycond3 (else3 #t)) => #t

Right. At the top level, else3 was unbound so it matches.

> (define else3)
> (mycond3 (else3 #t)) => syntax violation

Now it's bound, so, else3 at the top level has a different
binding from else3 in (foo), so, they two else3s are not
free-identifier=?.

> If you do the same for 'else' there is no syntax violation, as
> 'else' is exported as auxiliary syntax.

If you redefine else, you should get a syntax violation.

 > (library (foo)
     (export mycond3)
     (import (rnrs))
     (define-syntax mycond3
       (syntax-rules (else) [(_ (else e)) e])))
 > (import (foo))
 > (mycond3 (else 12))
12
 > (define else 17)
 > (mycond3 (else 12))
Unhandled exception
  Condition components:
    1. &message: "invalid syntax"
    2. &syntax:
        form: (mycond3 (else 12))
        subform: #f
    3. &trace: #<syntax (mycond3 (else 12))>

> I however see no way for a user to export
> his own auxiliary syntax, and hence the syntax violation.

Auxiliary keywords can be defined as

(define-syntax else3
   (lambda (x)
     (syntax-violation #f "incorrect usage of auxiliary keyword" x))