Puzzled by (let examples in the documentation
Posted: Sat Sep 23, 2006 11:13 pm
The examples given for the use of (let are leaving me confused. I think I understand what (let is for, but in the context of the example, isn't it unnecessary?
Wouldn't this make more sense in defining a sum-of-squares routine?
I know it doesn't demonstrate the use of (let, but (let seems unnecesssary: I checked, and a and b don't seem to be affected outside this function. So what's the point of using (let to isolate values here? Or is it just an artificial example and I shouldn't worry so much? ;-)
Code: Select all
(define (sum-sq a b)
(let ((x (* a a)) (y (* b b)))
(+ x y)))
(sum-sq 3 4) → 25
(define (sum-sq a b) ; alternative syntax
(let (x (* a a) y (* b b))
(+ x y)))
Code: Select all
(define (sum-sq a b)
(+ (* a a) (* b b)))