[plt-scheme] eval and interaction-enviroment in R5RS

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Nov 7 08:42:25 EST 2008

At Fri, 07 Nov 2008 09:14:09 +0100, Bas Steunebrink wrote:
> I was a bit puzzled when I tried the following code in DrScheme:
> (define x 0)
> (let ((x 1))
>     (eval '(set! x 2) (interaction-environment))
>     x)
> x
> When running this in R5RS mode, it outputs 1 and then 2, while I would 
> expect 2 and then 0. About interaction-environment, R5RS states that 
> "The intent is that this procedure will return the environment in which 
> the implementation would evaluate expressions dynamically typed by the 
> user". 

Although R5RS leaves the details to implementations, I believe the
intent behind the R5RS description is that `interaction-environment'
mimics a top-level read-eval-print loop. (All R5RS implementations that
I know implement it that way.)

> So I expected the set! expression to work on the local x 
> variable, while PLT appears to take the top-level one. What do you think?

See also


That explanation is specific to PLT Scheme, and it relies on a default
second argument to `eval' that is essentially
`(interaction-environment)'. But `eval' in a typical Scheme behaves the
way for the same reason.


Posted on the users mailing list.