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

  1. Path: sparky!uunet!cs.utexas.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: <oeeC4oG00awM0Eim9c@andrew.cmu.edu>
  6. Date: 5 Sep 92 08:32:52 GMT
  7. Article-I.D.: andrew.oeeC4oG00awM0Eim9c
  8. References: <shrchin.715636752@reading> <Iedzvq_00VIBMC7kwP@andrew.cmu.edu>
  9.     <shrchin.715668205@reading>
  10. Organization: Junior, Math/Computer Science, Carnegie Mellon, Pittsburgh, PA
  11. Lines: 85
  12. In-Reply-To: <shrchin.715668205@reading>
  13.  
  14. Excerpts from netnews.comp.lang.scheme: 5-Sep-92 Re: trampolines
  15. Jonathan H. N. Chin@csug (3077)
  16. > Rats. Thought I had tested that code. Obviously not. Okay then. How about
  17. > we add another level thus:
  18.  
  19. > (define make-trampoline[2]
  20. >   (lambda (proc)
  21. >     (letrec ((dummy (lambda()
  22. >                       (let ((result (proc)))
  23. >                         (begin
  24. >                           (set! dummy (lambda()
  25. >                                         result))
  26. >                            result)))))
  27. >       (lambda()
  28. >         (dummy)))))
  29.  
  30. > I tried this code, and it worked (or at least it seemed to... 8^).
  31.  
  32. > However, I now have an extra layer of indirection -- the extra function call.
  33. > So, have I just lost the advantage of removing the test in the first place?
  34.  
  35. > I tend to think in C terms. Would I be correct to think that in code such as:
  36.  
  37. > (define x 0)
  38. > (define trampoline (make-trampoline (lambda()
  39. >                                       (+ x 1)))) 
  40.  
  41. > that `trampoline' "points to" the closure created by the `letrec', rather
  42. > than pointing to `the-promise' which points to the closure. And hence when
  43. > `the-promise' changes, there is no affect on `trampoline'. Something like:
  44.  
  45. >                      trampoline
  46.  
  47. >                          |
  48. >                          v
  49.  
  50. >    the-promise  -->  #<closure>
  51.  
  52. > instead of:
  53.  
  54. >    trampoline --> the-promise --> #<closure>
  55.  
  56. > The question I then have is why does changing `dummy' in `make-trampoline[2]'
  57. > affect the closure "(lambda() (dummy))" although changes to `the-promise'
  58. > in the definition of `trampoline' (substituting `make-trampoline' for
  59. > `make-trampoline[2]') are *not* propagated?
  60.  
  61. Because (lambda () (dummy)) is an object which holds a 'pointer' to the
  62. variable 'dummy' whereas 'the-promise' is an object which only holds
  63. the value of the promise !
  64. In the lambda, the dummy won't be substituted with its value, but
  65. with a 'pointer' to its value ! this additional level of indirection permits
  66. the 'propagation'
  67.  
  68. > From my previous post:
  69. > 1) What prevents the R^4 `make-promise' from recursing indefinitely?
  70.  
  71. Termination of make-promise is not a problem: it returns a procedure.
  72. When you try to get the value of the promise, termination is directly
  73. dependant of termination of the evaluation of the promise.
  74. That seems logical !
  75. But the second if is necessary, because the promise may refer recursively
  76. to its value (and terminate cause the recursive call is dependant of an
  77. external variable, for example)
  78.  
  79. > and now
  80. > 2) Does `make-trampoline[2]' save over `make-promise' ?
  81. > 3) If (2), how do I extend `make-trampoline[2]' to allow promises that
  82. >    refer to their values?
  83.  
  84. > Thanks again,
  85. > Jonathan
  86. > -- 
  87. > Jonathan H N Chin (9 kyu) \ Dept. of Cybernetics, \ "Respondeo, etsi mutabor"
  88. > shrchin@uk.ac.rdg.susssys1 \ University of Reading \
  89. > bq305@cleveland.freenet.edu \ Box 225, Whiteknights \ < Rosenstock-Huessy >
  90. > jockstrap,mandy@CyberSpaceII \ Reading, RG6 2AY, U K \
  91.  
  92.  
  93.     Stefan Monnier
  94.  
  95.  
  96. -----------------------------------------------------
  97. -- On the average, people seem to be acting normal --
  98. -----------------------------------------------------
  99.