So, I know that in Scheme define for dynamic overview and for static coverage, but the following confuses me:
If i have
(let ((x 0))
(define f (lambda () x))
(display (f))
(let ((x 1))
(display (f))
)
)
It will display 00. So far so good. However, if I add an additional definition for x, for example:
(let ((x 0))
(define f (lambda () x))
(display (f))
(define x 4)
(let ((x 1))
(display (f))
)
)
Undefined4 is displayed. Why is this? Why does the definition of x after evaluating f affect the return value (f)? And why is this return value "undefined"?
It's also worth mentioning that linking f to letrec instead of define will also work:
(let ((x 0))
(letrec ((f (lambda () x)))
(display (f))
(define x 4)
(let ((x 1))
(display (f))
)
)
)
Returns 00.
Note. I used DrRacket with the language set to "Pretty Big"
source
share