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

  1. Path: sparky!uunet!olivea!spool.mu.edu!yale.edu!ira.uka.de!Sirius.dfn.de!news.DKRZ-Hamburg.DE!rzsun2.informatik.uni-hamburg.de!rzdspc23!a2vogler
  2. From: a2vogler@rzdspc23.informatik.uni-hamburg.de (Christian Vogler)
  3. Newsgroups: comp.lang.scheme
  4. Subject: Something I don't understand about bindings
  5. Message-ID: <a2vogler.724431792@rzdspc23>
  6. Date: 15 Dec 92 15:03:12 GMT
  7. Sender: news@informatik.uni-hamburg.de (Mr. News)
  8. Organization: University of Hamburg, FRG
  9. Lines: 29
  10.  
  11. Hi folks!
  12.  
  13. While working through the book "Structure and Interpretation of
  14. Computer Programs" by Abelson/Sussman, I found a piece of code
  15. I can't explain (p. 49/50).
  16. The following fragment is supposed to measure how much time
  17. execution of the procedure took (assuming that there is a
  18. runtime primitive):
  19.  
  20. (define (timed-prime-test n)
  21.   (define start-time (runtime))
  22.   (define found-prime? (prime? n))
  23.   (define elapsed-time (- (runtime) start-time))
  24.   (print n)
  25.   (cond (found-prime?
  26.          (print " *** ")
  27.          (print elapsed-time))))
  28.  
  29. The procedure then correctly prints the elapsed time for finding
  30. a prime number, but why does this work? Why is the (runtime) in
  31. the definition of start-time being evaluated at once, when the
  32. procedure (timed-prime-test) is entered, while the
  33. (runtime) in the definition of elapsed-time apparently is not evaluated
  34. before it actually is printed?
  35.  
  36. Any hints are appreciated.
  37.  
  38. with regards
  39.        Christian
  40.