home *** CD-ROM | disk | FTP | other *** search
- 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
- From: a2vogler@rzdspc23.informatik.uni-hamburg.de (Christian Vogler)
- Newsgroups: comp.lang.scheme
- Subject: Something I don't understand about bindings
- Message-ID: <a2vogler.724431792@rzdspc23>
- Date: 15 Dec 92 15:03:12 GMT
- Sender: news@informatik.uni-hamburg.de (Mr. News)
- Organization: University of Hamburg, FRG
- Lines: 29
-
- Hi folks!
-
- While working through the book "Structure and Interpretation of
- Computer Programs" by Abelson/Sussman, I found a piece of code
- I can't explain (p. 49/50).
- The following fragment is supposed to measure how much time
- execution of the procedure took (assuming that there is a
- runtime primitive):
-
- (define (timed-prime-test n)
- (define start-time (runtime))
- (define found-prime? (prime? n))
- (define elapsed-time (- (runtime) start-time))
- (print n)
- (cond (found-prime?
- (print " *** ")
- (print elapsed-time))))
-
- The procedure then correctly prints the elapsed time for finding
- a prime number, but why does this work? Why is the (runtime) in
- the definition of start-time being evaluated at once, when the
- procedure (timed-prime-test) is entered, while the
- (runtime) in the definition of elapsed-time apparently is not evaluated
- before it actually is printed?
-
- Any hints are appreciated.
-
- with regards
- Christian
-