home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / scheme / 2149 < prev    next >
Encoding:
Internet Message Format  |  1992-09-07  |  2.3 KB

  1. 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+
  2. From: sm86+@andrew.cmu.edu (Stefan Monnier)
  3. Newsgroups: comp.lang.scheme
  4. Subject: Re: trampolines
  5. Message-ID: <Iedzvq_00VIBMC7kwP@andrew.cmu.edu>
  6. Date: 4 Sep 92 16:27:34 GMT
  7. Article-I.D.: andrew.Iedzvq_00VIBMC7kwP
  8. References: <shrchin.715636752@reading>
  9. Organization: Junior, Math/Computer Science, Carnegie Mellon, Pittsburgh, PA
  10. Lines: 50
  11. In-Reply-To: <shrchin.715636752@reading>
  12.  
  13. Excerpts from netnews.comp.lang.scheme: 4-Sep-92 trampolines Jonathan H.
  14. N. Chin@csug (2303)
  15. > Ignoring promises that refer to their own values, it seems that the
  16. > above code would after the first "force" always have to perform a
  17. > redundant `if' test of `result-ready?'.  I should have thought that
  18. > this requirement could be removed, and the code I have tried seems to
  19. > do this:
  20.  
  21. > (define make-trampoline
  22. >   (lambda (proc)
  23. >     (letrec ((the-promise (lambda()
  24. >                             (let ((result (proc)))
  25. >                               (begin
  26. >                                 (set! the-promise (lambda()
  27. >                                                     result))
  28. >                                 result)))))
  29. >       the-promise)))
  30.  
  31. > where `make-trampoline' is used in place of `make-promise'.
  32. > (aside: what would be a reasonable way to reformat the above?)
  33.  
  34. > How would I need to modify this code to encompass promises that refer
  35. > to their own values?
  36.  
  37. > Thanks in advance,
  38. > Jonathan
  39.  
  40. The problem here, is that the final 'the-promise' returns
  41. the value of 'the-promise' but not 'the-promise' itself.
  42.  
  43. Now, imagine, you use that function. You get a promise
  44. You call it x. When you want to get his value, you force
  45. it by (x). The application of x will change the value of 'the-promise'
  46. but not that of x !!!
  47. So that at next (x), the same processing will be done
  48.  
  49. This way, you don't need the 'if ready' but you also evaluate
  50. each time from scratch !
  51. It is not delayed-evaluation !
  52.  
  53. Bad Luck !
  54.  
  55.     Stefan Monnier
  56.  
  57. PS: the R4RS version is not really stupid ! a better scheme-only
  58.     version is difficult to do !
  59.  
  60. -----------------------------------------------------
  61. -- On the average, people seem to be acting normal --
  62. -----------------------------------------------------
  63.