[Top][All Lists]

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

Re: Strange behavior with delayed objects

From: user8472
Subject: Re: Strange behavior with delayed objects
Date: Tue, 4 May 2010 09:59:55 -0700 (PDT)

Thanks for your reply. Yes, SICP introduces "let*" in chapter 4.1. The
current exercise is in chapter 3.5, though ;^)

Your suggestion is definitely a step in the right direction. However, it
does not yet solve the problem. The code
  (define (solve f y0 dt)
    (let* ((y (integral (delay dy) y0 dt))
           (dy (stream-map f y)))
  (stream-cdr (solve (lambda (x) x) 1 0.001))

still produces the error message:
streams.scm:609:21: In expression (force delayed-integrand):
streams.scm:609:21: Unbound variable: dy
ABORT: (unbound-variable)

According to R5RS (quote) "the 'let*' is similar to 'let', but the bindings
are performed sequentially from left to right [...] Thus the second binding
is done in an environment in which the first binding is visible, and so on."
To my understanding, this implies that the binding of "y" is done in an
environment visible to "dy", but not vice versa. (Equivalent to nested "let"

R5RS talks about another method named "letrec" which appears to do what I
want. However, when replacing "let*" by "letrec" above, the error message of
  (solve (lambda (x) x) 1 0.001)

streams.scm:601:14: While evaluating arguments to stream-map in expression
(stream-map f y):
streams.scm:601:14: Variable used before given a value: y
ABORT: (unbound-variable)

So something is still not quite right.

Linas Vepstas-3 wrote:
>> 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)
> [...]
> 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

View this message in context:
Sent from the Gnu - Guile - User mailing list archive at

reply via email to

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