guile-user
[Top][All Lists]
Advanced

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

Re: exporting procedure else now breaks case's else clause


From: mhw
Subject: Re: exporting procedure else now breaks case's else clause
Date: Sun, 14 Sep 2014 22:14:42 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Jan Nieuwenhuizen <address@hidden> writes:

> Hi,
>
> In stable-2.0, this works
>
>     (define-module (case) #:export (else))
>     (define (else ast) (if (> (length ast) 3) (cadddr ast) #f))
>     (define t 't) (case t ((t) #t) (else (eq? t 't)))
>
> with latest master it breaks as soon as else is added to the exports
> list:
>
>     ;;;
> /home/janneke/vc/verum/development/gaiag/module/gaiag/case.scm:9:31:
> case: invalid clause in subform (else (eq? t (quote t))) of (case t
> ((t) #t) (else (eq? t (quote t))))
>     language/cps/reify-primitives.scm:75:11: In procedure #<procedure
> 2477220 at ice-9/boot-9.scm:509:12 (expr clause clauses)>:
>     language/cps/reify-primitives.scm:75:11: Syntax error:
>     /home/janneke/vc/verum/development/gaiag/module/gaiag/case.scm:9:31:
> case: invalid clause in subform (else (eq? t (quote t))) of (case t
> ((t) #t) (else (eq? t (quote t))))
>
> Bug or feature?

Master's behavior here is correct.  According to both R6RS and R7RS,
syntax literals such as 'else' and '=>' match by comparing bindings
instead of names.  In other words, the binding for 'else' in effect
where the 'case' macro was defined must be the same as the binding for
'else' where you used the case macro, in order for it to match.  R6RS
also allows another way for the syntax literals to match: if 'else' is
unbound in both the definition and usage sites, then it suffices for
them to have the same name.

The intent in modern scheme is that these literals are treated like any
other bindings: 'else' and '=>' are exported from R6RS's (rnrs base) and
R7RS's (scheme base) libraries.  For example, you should be able to
rename these identifiers when you import them, and then use your
alternate names for them instead of the standard names.

For historical reasons, 'else' and '=>' are neither bound nor exported
from Guile's standard libraries, so we rely on the name-based matching
specified by R6RS.

The behavior of Guile 2.0.x is non-standard.  It matches syntax literals
if their names match and either (A) both have the same *non-toplevel*
binding, or (B) neither have a *non-toplevel* binding.  In other words,
in Guile 2.0.x, toplevel bindings are completely ignored for purposes of
matching syntax literals, and the names must match in all cases, so it's
not possible to rename syntax literals within a module.

     Regards,
       Mark



reply via email to

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