home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!news.aero.org!Aero.org!doner
- From: doner@Aero.org (John Doner)
- Newsgroups: comp.lang.scheme
- Subject: Re: Something I don't understand about bindings
- Date: 15 Dec 1992 17:03:04 GMT
- Organization: The Aerospace Corporation
- Lines: 28
- Distribution: world
- Message-ID: <1gl348INNp83@news.aero.org>
- References: <a2vogler.724431792@rzdspc23>
- NNTP-Posting-Host: armadillo.aero.org
-
- In article <a2vogler.724431792@rzdspc23>, a2vogler@rzdspc23.informatik.uni-hamburg.de (Christian Vogler) writes:
-
- |> 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?
- |>
-
- You are probably interpreting the define's as defining functions, whereas they
- are actually binding variables to new locations and assigning numeric values to
- those locations. The defines are evaluated sequentially, and all three of
- start-time, found-prime?, and elapsed-time have their values before the printing
- begins.
-