guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange behavior with delayed objects


From: Linas Vepstas
Subject: Re: Strange behavior with delayed objects
Date: Tue, 4 May 2010 10:21:53 -0500

On 4 May 2010 01:32, user8472 <address@hidden> wrote:
>
> I am currently working through SICP using Guile. I have found some strange
> behavior when doing the exercises in chapter 3.5. I am running Guile 1.4
> installed via Fink on Mac OS X 10.6, all latest patches installed. The
> problem also exists in Guile 1.8.6.
>
> This code works fine (and computes e):
>  (define y (integral (delay dy) 1 0.001))
>  (define dy (stream-map (lambda (x) x) y))
>  (stream-ref y 1000)
>
> The following code *should* be identical:
>  (define (solve f y0 dt)
>    (define y (integral (delay dy) y0 dt))
>    (define dy (stream-map f y))
>    y)
>  (solve (lambda (x) x) 1 0.001)
>
> But it yields the error message:
> 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)

You should use let*, not define, for this.

The problem is that when using define like this, there is no
gaurentee that th defines will be done in the order that
you typed them in.  This is the reason why let* exists -- so
that definitions can be done in the order in which they are
listed.  (it is not enough to use let, you must use let*)

I believe that SICP explains this somewhere ...

--linas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]