home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / scheme / 2746 < prev    next >
Encoding:
Internet Message Format  |  1992-12-15  |  1.6 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!news.aero.org!Aero.org!doner
  2. From: doner@Aero.org (John Doner)
  3. Newsgroups: comp.lang.scheme
  4. Subject: Re: Something I don't understand about bindings
  5. Date: 15 Dec 1992 17:03:04 GMT
  6. Organization: The Aerospace Corporation
  7. Lines: 28
  8. Distribution: world
  9. Message-ID: <1gl348INNp83@news.aero.org>
  10. References: <a2vogler.724431792@rzdspc23>
  11. NNTP-Posting-Host: armadillo.aero.org
  12.  
  13. In article <a2vogler.724431792@rzdspc23>, a2vogler@rzdspc23.informatik.uni-hamburg.de (Christian Vogler) writes:
  14.  
  15. |> The following fragment is supposed to measure how much time
  16. |> execution of the procedure took (assuming that there is a
  17. |> runtime primitive):
  18. |> 
  19. |> (define (timed-prime-test n)
  20. |>   (define start-time (runtime))
  21. |>   (define found-prime? (prime? n))
  22. |>   (define elapsed-time (- (runtime) start-time))
  23. |>   (print n)
  24. |>   (cond (found-prime?
  25. |>          (print " *** ")
  26. |>          (print elapsed-time))))
  27. |> 
  28. |> The procedure then correctly prints the elapsed time for finding
  29. |> a prime number, but why does this work? Why is the (runtime) in
  30. |> the definition of start-time being evaluated at once, when the
  31. |> procedure (timed-prime-test) is entered, while the
  32. |> (runtime) in the definition of elapsed-time apparently is not evaluated
  33. |> before it actually is printed?
  34. |> 
  35.  
  36. You are probably interpreting the define's as defining functions, whereas they
  37. are actually binding variables to new locations and assigning numeric values to
  38. those locations.  The defines are evaluated sequentially, and all three of 
  39. start-time, found-prime?, and elapsed-time have their values before the printing
  40. begins.
  41.