bartlett@WRL.DEC.COM (06/29/90)
In a previous message, Wayne Schou (math1205@waikato.ac.nz) suggested that the expression: (let ((a 1)) (define (f x) (define b (+ a x)) (define a 5) (+ a b)) (f 10)) should evaluate to either 20 or 16. >> 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? Disagree, according to R3RS,the effect of the program is undefined. Section 5.2.2 of R3RS defines internal defines in terms of letrec, so the above expression is really: (let ((a 1)) (letrec ((f (lambda (x) (letrec ((b (+ a x)) (a 5)) (+ a b))))) (f 10))) The last paragraph of section 4.2.2 of R3RS explains that a letrec of this form violates an important restriction. Quoting R3RS "it must be possible to evaluate each <init> without referring to the value of any <variable>. If this restriction is violated, then the effect is undefined, and an error may be signalled during the evaluation of the <init>s." >> Also in the DEC Scheme->C implementation the above expression returns the >> rather confusing value of 15. I assume this is caused by a having the value >> of 0 when the definition of b is evaluated. I think this is a bug! >> Who agrees/disagrees? Disagree as the value of the program is undefined. I will agree with you though that error signals on undefined operations are often more desirable than implementation specific values.