unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: user8472 <head_over_heels@freenet.de>
To: Guile-user@gnu.org
Subject: Re: Strange behavior with delayed objects
Date: Tue, 4 May 2010 09:59:55 -0700 (PDT)	[thread overview]
Message-ID: <28450337.post@talk.nabble.com> (raw)
In-Reply-To: <g2z3ae3aa421005040821y2fdf6e37iffe1ce381b2dd09d@mail.gmail.com>


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)))
      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"
blocks.)

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)

becomes
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: http://old.nabble.com/Strange-behavior-with-delayed-objects-tp28443452p28450337.html
Sent from the Gnu - Guile - User mailing list archive at Nabble.com.





  reply	other threads:[~2010-05-04 16:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-04  6:32 Strange behavior with delayed objects user8472
2010-05-04 15:21 ` Linas Vepstas
2010-05-04 16:59   ` user8472 [this message]
2010-05-05 14:53     ` Linas Vepstas
2010-05-07  8:09       ` user8472
2010-05-10 16:26         ` Linas Vepstas
2010-05-10 16:28           ` Linas Vepstas
2010-05-10 21:36           ` user8472
2010-05-10 22:08             ` Linas Vepstas
2010-05-21 10:52   ` Andy Wingo
2010-05-14 21:53 ` user8472
2010-05-21 10:59   ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=28450337.post@talk.nabble.com \
    --to=head_over_heels@freenet.de \
    --cc=Guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).