4 ms·
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
by shawn_w 6mo 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.
- projektfu 6mo agoPerhaps 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. (let ((inner (lambda (x) (+ x 3)))) (outer 5)) "7" But updating the definition of inner with set! or define changes the top-level definition.
- shawn_w 6mo agoYes, I was thinking of lexical scope; as in redefining the function shadows the existing one and doesn't change the function already defined uses of call.