Path: utzoo!attcan!uunet!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!eos!shelby!neon!max From: max@Neon.Stanford.EDU (Max Hailperin) Newsgroups: comp.lang.scheme Subject: Re: Internal Definitions Message-ID: <1990Jun29.155446.6681@Neon.Stanford.EDU> Date: 29 Jun 90 15:54:46 GMT References: <904.268b61d9@waikato.ac.nz> Organization: Computer Science Department, Stanford University Lines: 36 In article <904.268b61d9@waikato.ac.nz> math1205@waikato.ac.nz writes: >In a book by H. Abelson & G. Sussman entitled "Structure and Interpretation >of Computer Programs" (1985) there is a section on the evaluation of internal >definitions (pp. 439-442). In here they show there are several ways to evaluate >multiple internal definitions which can lead to inconsistent results when the >definitions reference each other. > >For example, the expression >(let ((a 1)) > (define (f x) > (define b (+ a x)) > (define a 5) > (+ a b)) > (f 10)) >can return different results depending on whether the definition of a and b >are evaluated simultaneously or in sequence; returning 20 or 16 resp. The book >suggests a simultaneous evaluation of definitions is the desired approach, but >because this is difficult to implement, they note the MIT implementors of >Scheme generate an error in the above case. >As I see the Scheme description given in R^nRS, expressions in the body of f >should be evaluated in sequence and therefore the above should return 16. > >Who agrees/disagrees? I disagree. Yes, the *expressions* in the body of f should be evaluated in sequence, but technically definitions are not expressions, if you read R^3R carefully. Definitions are treated differently; they are treated as a letrec. Letrec is defined such that it is an error, which the implementation *may* signal, to do something such as the example. If you used the actual formal semantics expansion, an error would indeed be signaled. But, it is explicitly sanctioned to omit this. Under this guise of a "non-signaled error," it is legal to extend the semantics to work the way you expect, and some implementations do. However, it is also equally legal to not signal the error, but do something else other than your sequential version. This explains the Scheme->C result you observed. Therefore, I disagree with you on that as well.