home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.scheme
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!news.udel.edu!udel!sbcs.sunysb.edu!hanche
- From: hanche@ams.sunysb.edu (Harald Hanche-Olsen)
- Subject: Re: Something I don't understand about bindings
- In-Reply-To: doner@Aero.org's message of 15 Dec 1992 17: 03:04 GMT
- Message-ID: <HANCHE.92Dec15134343@ptolemy.ams.sunysb.edu>
- Sender: usenet@sbcs.sunysb.edu (Usenet poster)
- Nntp-Posting-Host: ptolemy.ams.sunysb.edu
- Organization: University at Stony Brook, NY
- References: <a2vogler.724431792@rzdspc23> <1gl348INNp83@news.aero.org>
- Date: Tue, 15 Dec 1992 18:43:43 GMT
- Lines: 53
-
- >>>>> On 15 Dec 1992 17:03:04 GMT, doner@Aero.org (John Doner) said:
- John> NNTP-Posting-Host: armadillo.aero.org
-
- John> In article <a2vogler.724431792@rzdspc23>, a2vogler@rzdspc23.informatik.uni-hamburg.de (Christian Vogler) writes:
-
- John> |> The following fragment is supposed to measure how much time
- John> |> execution of the procedure took (assuming that there is a
- John> |> runtime primitive):
- John> |>
- John> |> (define (timed-prime-test n)
- John> |> (define start-time (runtime))
- John> |> (define found-prime? (prime? n))
- John> |> (define elapsed-time (- (runtime) start-time))
- John> |> (print n)
- John> |> (cond (found-prime?
- John> |> (print " *** ")
- John> |> (print elapsed-time))))
- John> |>
- John> |> The procedure then correctly prints the elapsed time for finding
- John> |> a prime number, but why does this work? [...]
-
- John> You are probably interpreting the define's as defining
- John> functions, whereas they are actually binding variables to new
- John> locations and assigning numeric values to those locations. The
- John> defines are evaluated sequentially, and all three of start-time,
- John> found-prime?, and elapsed-time have their values before the
- John> printing begins.
-
- That is not what r4rs says. Indeed the above code is completely
- equivalent to
-
- (define (timed-prime-test n)
- (letrec ((start-time (runtime))
- (found-prime? (prime? n))
- (elapsed-time (- (runtime) start-time)))
- (print n)
- (cond (found-prime?
- (print " *** ")
- (print elapsed-time)))))
-
- which should not work, in standard r4rs scheme. Not only is the order
- of evaluation in a letrec unspecified, but as it says in the section
- of internal defines:
-
- Just as for the equivalent \ide{letrec} expression, it must be
- possible to evaluate each \hyper{expression} of every internal
- definition in a \hyper{body} without assigning or referring to
- the value of any \hyper{variable} being defined.
-
- I can only conclude that the original poster uses a non-r4rs
- conforming scheme.
-
- - Harald
-