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

From: Bas Steunebrink (bass at cs.uu.nl)
Date: Fri Nov 7 09:42:40 EST 2008

Ah thanks for the link, Matthew. Initially it seemed to me that R5RS 
requires interaction-environment to be defined such that (eval (quote 
<expr>) (interaction-environment)) is always equivalent to just <expr>. 
However, the explanation in the PLT documentation convinced me this may 
not be a good requirement or even be impossible in general.


Matthew Flatt wrote:
> 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
>   http://docs.plt-scheme.org/guide/eval.html#(part._.Local_.Scopes)
> 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.
> Matthew

Bas Steunebrink
Intelligent Systems Group
Utrecht University
P.O. Box 80.089
3508TB Utrecht
The Netherlands
Tel: +31 (30) 253 2993

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20081107/4522f33b/attachment.html>

Posted on the users mailing list.