First of all, #lang racket is not Scheme, nor does it claim to be.
However, #lang r5rs does attempt to be Scheme, and it exhibits the same
behavior as #lang racket in this case, so your question is still valid.
I would argue that, in this case, Racket gets it right, and Bigloo and
Kawa are noncomformant.

In both R5RS and R7RS, the way syntax-rules matches “literals” is quite
explicit[1]:

  “[…] an input expression E matches a pattern P if and only if […]
   P is a literal identifier and E is an identifier with the same
   binding […]”

The wording “with the same binding” is important. This means literals
must not be matched by datum (that is, by their name) but by their
lexical binding. When you redefine `else`, you have created a new
binding that is distinct from the binding (or lack thereof) provided by
the Scheme standard library.

The `cond` form is listed as a “derived expression”, and an
implementation of `cond` using `syntax-rules` is provided by the
report[2]. However, it does not appear that Bigloo or Kawa properly
implement the same binding restriction mandated by the standard, so they
are nonconformant.

I also tested two other Schemes, somewhat randomly chosen. Chibi Scheme
exhibits the same incorrect behavior as Bigloo and Kawa, but Larceny has
the same behavior as Racket. It would be interesting to see what other
Schemes do, but the practical takeaway seems to be that this part of the
standard is inconsistently implemented, and you cannot depend on it if
you want to (for whatever reason) write portable Scheme.

[1]: http://docs.racket-lang.org/r5rs/r5rs-std/r5rs-Z-H-7.html#%_sec_4.3.2
[2]: http://docs.racket-lang.org/r5rs/r5rs-std/r5rs-Z-H-10.html#%_sec_7.3

> On Oct 27, 2016, at 15:46, Damien Mattei <damien.mat...@gmail.com> wrote:
> 
> Hi,
> 
> why this does not work with DrRacket:
> 
> #lang racket
> (define-syntax then
>  (syntax-rules ()
>    ((_ ev)  ev)
>    ((_ ev ...) (begin ev ...))))
> 
> (define-syntax else
>  (syntax-rules ()
>    ((_ ev)  ev)
>    ((_ ev ...) (begin ev ...))))
> 
> (if #f
>    (then 
>     1
>     2
>     3)
>    (else
>     3
>     4
>     5))
> 
> (cond (#f 'never)
>      (else 'always))
> 
> . else: bad syntax in: else
> 
> it works with others schemes as in bigloo or kawa:
> 
> ------------------------------------------------------------------------------
> Bigloo (4.1a)                                                            
> ,--^, 
> `a practical Scheme compiler'                                      _ ___/ /|/ 
>  
> Sam 26 sep 2015 04:59:46 CEST                                  ,;'( )__, ) '  
>  
> Inria -- Sophia Antipolis                                     ;;  //   L__.   
>  
> email: big...@lists-sop.inria.fr                              '   \    /  '   
>  
> url: http://www-sop.inria.fr/indes/fp/Bigloo                       ^   ^      
>  
> ------------------------------------------------------------------------------
> 
> 
> 1:=> (define-syntax then
>  (syntax-rules ()
>    ((_ ev)  ev)
>    ((_ ev ...) (begin ev ...))))
> #unspecified
> 1:=> (define-syntax else
>  (syntax-rules ()
>    ((_ ev)  ev)
>    ((_ ev ...) (begin ev ...))))
> #unspecified
> 1:=> (if #f
>    (then 
>     1
>     2
>     3)
>    (else
>     3
>     4
>     5))
> 5
> 1:=> (cond (#f 'never)
>      (else 'always))
> always
> 
> Damien

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to