home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.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 21:23:15 GMT
- Organization: The Aerospace Corporation
- Lines: 73
- Distribution: world
- Message-ID: <1glic3INNq5b@news.aero.org>
- References: <a2vogler.724431792@rzdspc23> <1gl348INNp83@news.aero.org> <HANCHE.92Dec15134343@ptolemy.ams.sunysb.edu>
- NNTP-Posting-Host: armadillo.aero.org
-
- In article <HANCHE.92Dec15134343@ptolemy.ams.sunysb.edu>, hanche@ams.sunysb.edu (Harald Hanche-Olsen) writes:
- |> >>>>> 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> |> (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
-
- You're right, it says there is an equivalent letrec expression, but isn't very
- precise about how to determine that. And indeed, the letrec order of evaluation is
- unspecified. On the other hand, his original define (again according to r4rs) is
- equivalent to
-
- (define timed-prime-test
- (lambda (n)
- (define start-time (runtime))
- (define found-prime? (prime? n))
- .
- .
- .
- ))
-
- So the sequence of expressions beginning with the inner defines is the body of
- a lambda expression. And r4rs says the expressions in the body of a lambda
- expression are to be evaluated sequentially.
-
- Now I don't know what to think.
-
- John
-