home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / scheme / 2754 < prev    next >
Encoding:
Text File  |  1992-12-15  |  2.6 KB  |  67 lines

  1. Newsgroups: comp.lang.scheme
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!news.udel.edu!udel!sbcs.sunysb.edu!hanche
  3. From: hanche@ams.sunysb.edu (Harald Hanche-Olsen)
  4. Subject: Re: Something I don't understand about bindings
  5. In-Reply-To: doner@Aero.org's message of 15 Dec 1992 17: 03:04 GMT
  6. Message-ID: <HANCHE.92Dec15134343@ptolemy.ams.sunysb.edu>
  7. Sender: usenet@sbcs.sunysb.edu (Usenet poster)
  8. Nntp-Posting-Host: ptolemy.ams.sunysb.edu
  9. Organization: University at Stony Brook, NY
  10. References: <a2vogler.724431792@rzdspc23> <1gl348INNp83@news.aero.org>
  11. Date: Tue, 15 Dec 1992 18:43:43 GMT
  12. Lines: 53
  13.  
  14. >>>>> On 15 Dec 1992 17:03:04 GMT, doner@Aero.org (John Doner) said:
  15. John> NNTP-Posting-Host: armadillo.aero.org
  16.  
  17. John> In article <a2vogler.724431792@rzdspc23>, a2vogler@rzdspc23.informatik.uni-hamburg.de (Christian Vogler) writes:
  18.  
  19. John> |> The following fragment is supposed to measure how much time
  20. John> |> execution of the procedure took (assuming that there is a
  21. John> |> runtime primitive):
  22. John> |> 
  23. John> |> (define (timed-prime-test n)
  24. John> |>   (define start-time (runtime))
  25. John> |>   (define found-prime? (prime? n))
  26. John> |>   (define elapsed-time (- (runtime) start-time))
  27. John> |>   (print n)
  28. John> |>   (cond (found-prime?
  29. John> |>          (print " *** ")
  30. John> |>          (print elapsed-time))))
  31. John> |> 
  32. John> |> The procedure then correctly prints the elapsed time for finding
  33. John> |> a prime number, but why does this work?  [...]
  34.  
  35. John> You are probably interpreting the define's as defining
  36. John> functions, whereas they are actually binding variables to new
  37. John> locations and assigning numeric values to those locations.  The
  38. John> defines are evaluated sequentially, and all three of start-time,
  39. John> found-prime?, and elapsed-time have their values before the
  40. John> printing begins.
  41.  
  42. That is not what r4rs says.  Indeed the above code is completely
  43. equivalent to
  44.  
  45.   (define (timed-prime-test n)
  46.     (letrec ((start-time (runtime))
  47.          (found-prime? (prime? n))
  48.          (elapsed-time (- (runtime) start-time)))
  49.       (print n)
  50.       (cond (found-prime?
  51.          (print " *** ")
  52.          (print elapsed-time)))))
  53.  
  54. which should not work, in standard r4rs scheme.  Not only is the order
  55. of evaluation in a letrec unspecified, but as it says in the section
  56. of internal defines:
  57.  
  58. Just as for the equivalent \ide{letrec} expression, it must be
  59. possible to evaluate each \hyper{expression} of every internal
  60. definition in a \hyper{body} without assigning or referring to
  61. the value of any \hyper{variable} being defined.
  62.  
  63. I can only conclude that the original poster uses a non-r4rs
  64. conforming scheme.
  65.  
  66. - Harald
  67.