marcomaggi / vicare

A native compiler for Scheme compliant with R6RS
http://marcomaggi.github.com/vicare.html
Other
200 stars 34 forks source link

detection of letrec and letrec* restrictions is a must #8

Closed marcomaggi closed 12 years ago

marcomaggi commented 14 years ago

The following test should succeed because the LETREC form is wrong:

(check
    (guard (E ((assertion-violation? E)
               #t)
              (else #f))
      (eval '(letrec ((c b)
                      (b a)
                      (a 12))
               c)
            (environment '(rnrs))))
  => #t)

Matches bug 216832 at the Ikarus bug tracker.

marcomaggi commented 12 years ago

Fixed in the HEAD of the assembler branch, by adding a compiler pass. The fix is not R6RS compatible. R6RS mandates that illegal references to bindings established by LETREC and LETREC* are detected at run time and cause an assertion violation to be raised. Vicare detects them at compile time, so some fully R6RS-compliant code will not work under Vicare.

For example, the following program (from Flatt's test suite) will run under a R6RS-compliant implementation:

 (import (rnrs))
 (letrec ((x (if (eq? (cons 1 2)
                      (cons 1 2))
                 x
               1)))
   x)

because the form X in reference position in the right-hand side of the binding is never evaluated; under Vicare this code will rather raise an assertion violation and syntax violation at compile time.