Subject: Re: Differences between SCM version 5c3 and SCM version 4e6
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 2000/06/17
Newsgroups: comp.lang.scheme
Message-ID: <8ienke$n90hm$1@fido.engr.sgi.com>
<svagera@atp.tuwien.ac.at> wrote:
+---------------
| Recently I received a Scheme program that was developed under SCM
| version 4e6 but refuses to run on my version (SCM version 5c3).
| The problem can be seen in the following example:
| >(define (double x) 
| >  (define y 2)
| >  (define z (* x y))
| >  (print z))
...
| SCM version 5e3 gives:
| > (double 3)
| ERROR: unbound variable:  y
+---------------

Well, technically, both results are allowed -- it's your code that's wrong.
According to R5RS, internal definitions are completely equivalent to
"letrec"s, so what your code "really" says is:

	(define (double x) 
	  (letrec ((y 2)
		   (z (* x y)))
	    (print z)))

But R5RS *also* clearly says:

	Just as for the equivalent letrec expression, it must be possible
	to evaluate each <expression> of every internal definition in a
	<body> without assigning or referring to the value of any <variable>
	being defined.
and:
	One restriction on letrec is very important: it must be possible to
	evaluate each <init> without assigning or referring to the value of
	any <variable>. If this restriction is violated, then it is an error.

The fact that SCM4e6 didn't complain was a fluke that you shouldn't rely on.


-Rob

p.s. Try rewriting your code using "let*", which DOES force sequential
evaluation [and incremental extending of the lexical environment]:

	(define (double x) 
	  (let* ((y 2)
	         (z (* x y)))
	    (print z)))

-----
Rob Warnock, 41L-955		rpw3@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		PP-ASEL-IA
Mountain View, CA  94043