Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set! creates new bindings #850

Open
ak-1 opened this issue Jun 28, 2024 · 3 comments
Open

set! creates new bindings #850

ak-1 opened this issue Jun 28, 2024 · 3 comments

Comments

@ak-1
Copy link

ak-1 commented Jun 28, 2024

My expectation was that

set! does not establish a new binding for var but rather alters the value of an existing binding.

However:

$ scheme
Chez Scheme Version 10.0.0
Copyright 1984-2024 Cisco Systems, Inc.

> x
Exception: variable x is not bound
Type (debug) to enter the debugger.
> (set! x 123)
> x
123
> (let () y)
Exception: variable y is not bound
Type (debug) to enter the debugger.
> (let () (set! y 456) y)
456
> 
@jltaylor-us
Copy link
Contributor

There are several differences between the Interaction Environment and RnRS environments. This is one of them.

All identifiers not bound in the initial interaction environment and not defined by the programmer are treated as "potentially bound" as variables to facilitate the definition of mutually recursive procedures.

@ak-1
Copy link
Author

ak-1 commented Jun 28, 2024

All identifiers not bound in the initial interaction environment and not defined by the programmer are
treated as "potentially bound" as variables to facilitate the definition of mutually recursive procedures.

After reading this I still would not expect this set! behavior.

I looked at various other scheme implementations. At least racket, guile and mit-scheme all allow mutually recursive definitions like yin / yang in their interaction environments, but do not allow to set! an unbound identifier.

If this is really intended in ChezScheme, maybe it should be stated explicitly in the user guide.

@LiberalArtist
Copy link
Contributor

At least racket, … [does] not allow to set! an unbound identifier.

This is true by default, but can be controlled using the compile-allow-set!-undefined parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants