gwatt / chez-exe

Chez Scheme self hosting executable
Other
179 stars 40 forks source link

Exception: attempt to reference unbound identifier ... #15

Closed divs1210 closed 3 years ago

divs1210 commented 3 years ago

I have a script that defines top-level bindings using define-top-level-value.

These scripts run fine when run via scheme --script myfile.scm but fail to compile under chez-exe with the exception:

Exception: attempt to reference unbound identifier ...

An example of such a script:

(import (scheme))

(define-top-level-value 'a 1)

(display a)

(newline)

What can I do to make this work?

Thanks!

gwatt commented 3 years ago

You should get the same behavior if you run scheme --program myfile.scm You'll have to use (top-level-value 'a) to get the value assigned to a, or use (define a) (display a) Chez-exe compiles a R6RS program, which will exclusively use lexical / static scope to resolve identifiers. Since a isn't defined until runtime it can't be located at compile time.

divs1210 commented 3 years ago

Thanks, that helps!