<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix"><tt>On 07/06/2013 08:07 PM, Nathan
Sorenson wrote:</tt><tt><br>
</tt></div>
<blockquote cite="mid:BAY163-W1813D2E7A1FE9D4FCCCCDBA7F0@phx.gbl"
type="cite">
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style>
<div dir="ltr"><tt><br>
</tt><tt>Another option would be to unwind all lets and lambdas
so each body only can contain one expression, such that</tt><tt><br>
</tt><tt><br>
</tt><tt>(let () 1 (define two 2) two) => (let () 1 (let ()
(two 2) two))</tt><tt><br>
</tt></div>
</blockquote>
<tt><br>
</tt><tt>Gambit follows R5RS, where internal defines are required to
be at the beginning of a lambda body (which a let body really is)
and where those defines are equivalent to a letrec. So the
following prints #t:</tt><tt><br>
</tt><tt><br>
</tt><tt>(let ()</tt><tt><br>
</tt><tt> (define (myeven? x)</tt><tt><br>
</tt><tt> (cond ((zero? x) #t)</tt><tt><br>
</tt><tt> ((< x 0) (myodd? (+ x 1)))</tt><tt><br>
</tt><tt> (else (myodd? (- x 1)))))</tt><tt><br>
</tt><tt> (define (myodd? x)</tt><tt><br>
</tt><tt> (cond ((zero? x) #f)</tt><tt><br>
</tt><tt> ((< x 0) (myeven? (+ x 1)))</tt><tt><br>
</tt><tt> (else (myeven? (- x 1)))))</tt><tt><br>
</tt><tt> (display (myodd? 3))</tt><tt><br>
</tt><tt> (newline))</tt><tt><br>
</tt><tt><br>
</tt><tt>and is equivalent to</tt><tt><br>
</tt><tt><br>
</tt><tt>(let ()</tt><tt><br>
</tt><tt> (letrec ((myeven?</tt><tt><br>
</tt><tt> (lambda (x)</tt><tt><br>
</tt><tt> (cond ((zero? x) #t)</tt><tt><br>
</tt><tt> ((< x 0) (myodd? (+ x 1)))</tt><tt><br>
</tt><tt> (else (myodd? (- x 1))))))</tt><tt><br>
</tt><tt> (myodd?</tt><tt><br>
</tt><tt> (lambda (x)</tt><tt><br>
</tt><tt> (cond ((zero? x) #f)</tt><tt><br>
</tt><tt> ((< x 0) (myeven? (+ x 1)))</tt><tt><br>
</tt><tt> (else (myeven? (- x 1)))))))</tt><tt><br>
</tt><tt> (display (myodd? 3))</tt><tt><br>
</tt><tt> (newline)))</tt><tt><br>
</tt><tt><br>
</tt><tt>Your transformation would mean that the binding of odd?
would not be visible to the definition of even?: Loading </tt><tt><br>
</tt><tt><br>
</tt><tt>(let ()</tt><tt><br>
</tt><tt> (define (myeven? x)</tt><tt><br>
</tt><tt> (cond ((zero? x) #t)</tt><tt><br>
</tt><tt> ((< x 0) (myodd? (+ x 1)))</tt><tt><br>
</tt><tt> (else (myodd? (- x 1)))))</tt><tt><br>
</tt><tt> (let ()</tt><tt><br>
</tt><tt> (define (myodd? x)</tt><tt><br>
</tt><tt> (cond ((zero? x) #f)</tt><tt><br>
</tt><tt> ((< x 0) (myeven? (+ x 1)))</tt><tt><br>
</tt><tt> (else (myeven? (- x 1)))))</tt><tt><br>
</tt><tt> (let ()</tt><tt><br>
</tt><tt> (display (myodd? 3))</tt><tt><br>
</tt><tt> (let ()</tt><tt><br>
</tt><tt> (newline)))))</tt><tt><br>
</tt><tt><br>
</tt><tt>gives</tt><tt><br>
</tt><tt><br>
</tt><tt>frying-pan:~> gsi crap.scm</tt><tt><br>
</tt><tt>*** ERROR IN myeven?, "crap.scm"@5.14 -- Unbound variable:
myodd?</tt><tt><br>
</tt><tt><br>
</tt><tt>I believe that systems that allow interleaving expressions
and definitions interpret a body using something called letrec*
semantics, but since I'm not clear what that entails, someone else
will need to explain it.</tt><tt><br>
</tt><tt><br>
</tt><tt>Brad</tt><tt><br>
</tt>
</body>
</html>