Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with circular definition in Scheme
    text
    copied!<p>I am currently working through SICP using Guile as my primary language for the exercises. I have found a strange behavior while implementing the exercises in chapter 3.5. I have reproduced this behavior using Guile 1.4, Guile 1.8.6 and Guile 1.8.7 on a variety of platforms and am certain it is not specific to my setup.</p> <p>This code works fine (and computes e):</p> <pre><code> (define y (integral (delay dy) 1 0.001)) (define dy (stream-map (lambda (x) x) y)) (stream-ref y 1000) </code></pre> <p>The following code <em>should</em> give an identical result:</p> <pre><code> (define (solve f y0 dt) (define y (integral (delay dy) y0 dt)) (define dy (stream-map f y)) y) (stream-ref (solve (lambda (x) x) 1 0.001) 1000) </code></pre> <p>But it yields the error message:</p> <pre><code>standard input:7:14: While evaluating arguments to stream-map in expression (stream-map f y): standard input:7:14: Unbound variable: y ABORT: (unbound-variable) </code></pre> <p>So when embedded in a procedure definition, the (define y ...) does not work, whereas outside the procedure in the global environment at the REPL it works fine.</p> <p>What am I doing wrong here? I can post the auxiliary code (i.e., the definitions of integral, stream-map etc.) if necessary, too. With the exception of the system-dependent code for cons-stream, they are all in the book. My own implementation of cons-stream for Guile is as follows:</p> <pre><code>(define-macro (cons-stream a b) `(cons ,a (delay ,b))) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload