I'm working through SICP and have implemented exercise 1.11 (Pascal's Triangle). What I'm curious about here is performance considerations by defining functions within the main function. I would assume they get reassigned with each invocation of the function. In saying that, this style appeals to me, as the functionality is scoped to the main function, and lexical scoping is used to effect. Obviously I'm a scheme noob so please go nuts in tearing this code apart.
(define (pascal-value row elem) (define (out-of-range?) (or (> elem row) (< elem 1))) (define (edge?) (or (= row elem) (= elem 1))) (cond ((edge?) 1) ((out-of-range?) 0) (else (+ (pascal-value (- row 1) (- elem 1)) (pascal-value (- row 1) elem)))))