home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!uwm.edu!ogicse!das-news.harvard.edu!cantaloupe.srv.cs.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!sm86+
- From: sm86+@andrew.cmu.edu (Stefan Monnier)
- Newsgroups: comp.lang.scheme
- Subject: Re: trampolines
- Message-ID: <Iedzvq_00VIBMC7kwP@andrew.cmu.edu>
- Date: 4 Sep 92 16:27:34 GMT
- Article-I.D.: andrew.Iedzvq_00VIBMC7kwP
- References: <shrchin.715636752@reading>
- Organization: Junior, Math/Computer Science, Carnegie Mellon, Pittsburgh, PA
- Lines: 50
- In-Reply-To: <shrchin.715636752@reading>
-
- Excerpts from netnews.comp.lang.scheme: 4-Sep-92 trampolines Jonathan H.
- N. Chin@csug (2303)
- > Ignoring promises that refer to their own values, it seems that the
- > above code would after the first "force" always have to perform a
- > redundant `if' test of `result-ready?'. I should have thought that
- > this requirement could be removed, and the code I have tried seems to
- > do this:
-
- > (define make-trampoline
- > (lambda (proc)
- > (letrec ((the-promise (lambda()
- > (let ((result (proc)))
- > (begin
- > (set! the-promise (lambda()
- > result))
- > result)))))
- > the-promise)))
-
- > where `make-trampoline' is used in place of `make-promise'.
- > (aside: what would be a reasonable way to reformat the above?)
-
- > How would I need to modify this code to encompass promises that refer
- > to their own values?
-
- > Thanks in advance,
- > Jonathan
-
- The problem here, is that the final 'the-promise' returns
- the value of 'the-promise' but not 'the-promise' itself.
-
- Now, imagine, you use that function. You get a promise
- You call it x. When you want to get his value, you force
- it by (x). The application of x will change the value of 'the-promise'
- but not that of x !!!
- So that at next (x), the same processing will be done
-
- This way, you don't need the 'if ready' but you also evaluate
- each time from scratch !
- It is not delayed-evaluation !
-
- Bad Luck !
-
- Stefan Monnier
-
- PS: the R4RS version is not really stupid ! a better scheme-only
- version is difficult to do !
-
- -----------------------------------------------------
- -- On the average, people seem to be acting normal --
- -----------------------------------------------------
-