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
823 stars 42 forks source link

`guard`'s cond clauses evalued in unexpected dynamic environment #491

Open okuoku opened 2 years ago

okuoku commented 2 years ago

tested: https://github.com/justinethier/cyclone/commit/cf66cf1057fcd687cc42d4d7dcaeeef00cba089b

It seems guard syntax evaluates its cond clause s in wrong dynamic environment. e.g.)

(define p0 (make-parameter 1))
(guard
  (c (#t
      (display (list (p0) '== 1)) (newline)))
  (parameterize ((p0 2))
                (display (list (p0) '== 2)) (newline)
                (raise 'unused)))

should print

(2 == 2)
(1 == 1)

but it prints

(2 == 2)
(2 == 1)

R7RS specifies dynamic environment here as:

That implicit cond expression is evaluated with the continuation and dynamic environment of the guard expression.

justinethier commented 2 years ago

Thanks for the report @okuoku, I'll look into this.