On 2-Feb-08, at 6:35 PM, James Long wrote:
For example, the following simple scenario doesn't work with gambit:
-- test.scm
(namespace ("foo#")) (##include "~~/lib/gambit#.scm")
(define a 5)
(namespace ("bar#")) (##include "~~/lib/gambit#.scm") (namespace ("foo#" a))
(eval '(display a))
Of course it doesn't work! You are mixing two different levels of evaluation. What you should have written is:
(namespace ("foo#")) (##include "~~/lib/gambit#.scm")
(define a 5)
(eval '(let () (namespace ("bar#")) (##include "~~/lib/gambit#.scm") (namespace ("foo#" a)) (display a)))
Note that the semantics you were expecting requires dynamic binding. In other words, for the call to "eval", the caller's namespace environment must be accessed by the callee (eval in this case). This inheritance of the namespace environment would be very messy. For example consider:
(namespace ("foo#")) (##include "~~/lib/gambit#.scm")
(define a 5) (define e eval) (define (f x) (e x)) (define (g) (f '(display a)))
(namespace ("bar#")) (##include "~~/lib/gambit#.scm") (namespace ("foo#" a g))
(define (f x) x)
(eval '(display a)) (g)
Does the call to g return the same result as the call to eval? When g calls f, which f is called... foo#f or bar#f? For lexical scoping we want it to call foo#f, but if the callee (i.e. g) inherits the namespace environment of the caller, then the f evaluated in g should resolve to foo#f. This is madness!
Marc