Comment by shawn_w
9 hours ago
You know, after some testing with a bunch of different scheme implementations, I take back what I said, at least for working in a REPL.
(define (displayln msg) (display msg) (newline))
(define (inner x) (+ x 1))
(define (outer x) (inner x))
(displayln (outer 5))
(define (inner x) (+ x 2))
(displayln (outer 5))
outputs 6 and 7 in every one I tried, not the 6 and 6 I expected.
Perhaps you were thinking of lexical scope vs dynamic scope? Lexical scoping would prevent a local definition of inner from changing the definition used in outer.
But updating the definition of inner with set! or define changes the top-level definition.