justinethier / cyclone

:cyclone: A brand-new compiler that allows practical application development using R7RS Scheme. We provide modern features and a stable system capable of generating fast native binaries.
http://justinethier.github.io/cyclone/
MIT License
824 stars 44 forks source link

Problems with lexical scoping #13

Open justinethier opened 9 years ago

justinethier commented 9 years ago

Need to be able to prevent collisions with special form symbols. For example:

(import (scheme base) (scheme write))
(let ((if write))
  (if 1)
  (set! if (lambda (a b c) (write (list a b c))))
  (if 1 2 3))

Note this should also work without the let, in both the compiler and interpreter.

justinethier commented 7 years ago

Other examples that yield the wrong results:

(define-syntax orr (syntax-rules () ((orelse <expr1> <expr2>) (let ((temp <expr1>)) (if temp temp <expr2>)))))
(let ((if +)) (if (orr 1 1) 10 100)) => 10 instead of 111
(let ((if +)) (if 1 2 3)) => 2 instead of 6
justinethier commented 7 years ago

It should be possible to check for this during alpha conversion. For example, do not go into the if? branch for an expression when there is a local variable if.