marcomaggi / vicare

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

Order of defines now more restricted? #83

Closed svenha closed 8 years ago

svenha commented 8 years ago

It seems to me that in past months vicare has become much stricter about order of defines. The following code cannot be loaded into vicare anymore.

(define (cartesian-product l1 . l) (if (null? l) (map list l1) (cartesian-product2 l1 (apply cartesian-product l))))

(define (cartesian-product2 l1 l2) (let ((result '())) (let loop ((l0 l1)) (if (null? l0) result (let* ((x1 (car l0)) (result2 (map (lambda (x2) (cons x1 x2)) l2))) (cond ((pair? result2) (cond ((null? result) (set! result result2)) (else (append! result result2))))) (loop (cdr l0)))))))

vicare Vicare Scheme version 0.4d0, 64-bit Build 2015-11-12

Copyright (c) 2006-2010 Abdulaziz Ghuloum and contributors Copyright (c) 2011-2015 Marco Maggi and contributors

vicare> (load "bugvicare-a.scm") Unhandled exception Condition components:

  1. &who: cartesian-product2
  2. &message: "unbound identifier"
  3. &undefined
  4. &syntax: form: #<syntax expr=(cartesian-product2 l1 (apply cartesian-product l)) mark=(src) line=4 column=5 source=bugvicare-a.scm> subform: #<syntactic-identifier expr=cartesian-product2 mark=(src) line=4 column=6 source=bugvicare-a.scm>
  5. &source-position: port-id: "bugvicare-a.scm" byte: 73 character: 73 line: 4 column: 5
  6. &macro-expansion-trace: #<syntax expr=(cartesian-product2 l1 (apply cartesian-product l)) mark*=(src) line=4 column=5 source=bugvicare-a.scm>
marcomaggi commented 8 years ago

I see the problem. It also happens with this simpler file:

(define (b) (a))
(define (a) 1)

and, in the end, it depends upon the following code raising the error when evaluating the first form:

(eval '(define (b) (a)) (interaction-environment))
(eval '(define (a) 1)   (interaction-environment))

which is what load does internally.

marcomaggi commented 8 years ago

I have pushed on the master branch a change that should mitigate the problem. Syntactic bindings established in a single load file can be defined in any order allowed by a body. Syntactic identifiers in reference position must resolve to syntactic bindings in the current load file or an already loaded load file.