<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.7600.16625"></HEAD>
<BODY>
<DIV><FONT size=2 face="Courier New"><SPAN
class=694263510-18092010>Hi,</SPAN></FONT></DIV>
<DIV><FONT size=2 face="Courier New"><SPAN
class=694263510-18092010></SPAN></FONT> </DIV>
<DIV><FONT size=2 face="Courier New"><SPAN class=694263510-18092010>Section 11.3
of R6RS states: "An expanded <body> (see chapter 10) containing variable
definitions can always be converted into an equivalent letrec* expression." The
semantics of letrec* includes "each <variable> is assigned in
left-to-right order". This I interpret as allowing an internal definition to
refer to the value of a previously defined variable.
However:</SPAN></FONT></DIV>
<DIV><FONT size=2 face="Courier New"><SPAN
class=694263510-18092010></SPAN></FONT> </DIV>
<DIV><FONT size=2 face="Courier New"><SPAN
class=694263510-18092010>#!r6rs</SPAN></FONT></DIV>
<DIV><FONT size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT size=2 face="Courier New"><SPAN
class=694263510-18092010>(import<BR> (rnrs base (6))<BR> (rnrs io
simple (6)))</SPAN></FONT></DIV>
<DIV><FONT size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT size=2 face="Courier New"><SPAN class=694263510-18092010>(define
(a)<BR> (define (b) "who cares?")<BR> (define c (b))<BR>
c)</SPAN></FONT></DIV>
<DIV><FONT size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT size=2 face="Courier New"><SPAN class=694263510-18092010>(write
(a))</SPAN></FONT></DIV>
<DIV><FONT size=2 face="Courier New"><SPAN
class=694263510-18092010></SPAN></FONT> </DIV>
<DIV><FONT size=2 face="Courier New"><SPAN
class=694263510-18092010>Produces:</SPAN></FONT></DIV>
<DIV><FONT size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT size=2 face="Courier New"><SPAN class=694263510-18092010>Welcome to
DrRacket, version
5.0.1.5--2010-09-13(5b54caebb066920e2585244a5ee444a3f121c966/a)
[3m].<BR>Language: r6rs; memory limit: 2000 MB.<BR>. . procedure application:
expected procedure, given: #<undefined> (no arguments)</SPAN></FONT></DIV>
<DIV><FONT size=2 face="Courier New"><SPAN
class=694263510-18092010></SPAN></FONT> </DIV>
<DIV><FONT size=2 face="Courier New"><SPAN class=694263510-18092010>The code
expands as follows. The hot spots is marked with an arrow.</SPAN></FONT></DIV>
<DIV><FONT size=2 face="Courier New"><SPAN
class=694263510-18092010></SPAN></FONT> </DIV>
<DIV><FONT size=2 face="Courier New"><SPAN class=694263510-18092010>(module
anonymous-module r6rs<BR> (#%plain-module-begin<BR> (#%require
r6rs/private/prelims)<BR> (#%require (lib
"rnrs/base-6.rkt"))<BR> (#%require (for-meta #f (lib
"rnrs/base-6.rkt")))<BR> (#%require (lib
"rnrs/io/simple-6.rkt"))<BR> (#%require (for-meta #f (lib
"rnrs/io/simple-6.rkt")))<BR> (define-values
(a)<BR>
(#%plain-lambda<BR>
()<BR> (let-values (((b) undefined) ((c)
undefined))<BR> (let-values ;
<====== prohibits reference to value of previously
defined var<BR>
(((newtemp)<BR>
(#%plain-lambda () (letrec-values () (let-values () '"who
cares?"))))<BR>
((newtemp:19) (#%app b))) ;
<======<BR> (set! b
newtemp)<BR> (set! c
newtemp:19)<BR>
(let-values:20 () (let-values:21 () c))))))<BR> (#%app write (#%app
a))))<BR></SPAN></FONT></DIV>
<DIV><SPAN class=694263510-18092010><SPAN class=694263510-18092010><FONT size=2
face="Courier New">Is this a bug or do I misunderstand
R6RS?</FONT></SPAN></SPAN></DIV>
<DIV><FONT size=2 face="Courier New"><SPAN class=694263510-18092010>The
following works correct:</SPAN></FONT></DIV>
<DIV><FONT size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT size=2 face="Courier New">#!r6rs</FONT></DIV>
<DIV><FONT size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT size=2 face="Courier New">(import<BR> (rnrs base
(6))<BR> (rnrs io simple (6)))</FONT></DIV>
<DIV><FONT size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT size=2 face="Courier New">(define (a)<BR>
(letrec*<BR> ((b (lambda () "who cares?"))<BR> (c
(b)))<BR> c))</FONT></DIV>
<DIV><FONT size=2 face="Courier New"></FONT> </DIV>
<DIV><FONT size=2 face="Courier New">(write (a))</FONT></DIV>
<DIV><FONT size=2 face="Courier New"></FONT> </DIV>
<DIV><SPAN class=694263510-18092010><FONT size=2 face="Courier New">Thanks,
Jos</FONT></SPAN></DIV></BODY></HTML>