[gambit-list] why does load/include work differently for this function?
lowly coder
lowlycoder at huoyanjinjing.com
Fri Aug 14 17:20:15 EDT 2009
~/test:$ cat lookup-var.scm
(define (lookup-var var-name)
(##define-macro (macro-code-cte c)
`(##vector-ref ,c 2))
(##define-macro (macro-rte-up rte)
`(##vector-ref ,rte 0))
(define (the-env)
(##continuation-capture
(lambda (cont)
(if (##interp-continuation? cont)
(let (($code (##interp-continuation-code cont))
(rte (##interp-continuation-rte cont)))
(cons (macro-code-cte $code) rte))
(error "the-env must be called from interpreted code")))))
(define (env-ref env var)
(let loop1 ((c (car env))
(r (cdr env)))
(cond ((##cte-top? c)
(##global-var-ref (##make-global-var var)))
((##cte-frame? c)
(let loop2 ((vars (##cte-frame-vars c))
(i 1))
(if (pair? vars)
(if (eq? var (##car vars))
(vector-ref r i)
(loop2 (cdr vars)
(+ i 1)))
(loop1 (##cte-parent-cte c)
(macro-rte-up r)))))
(else
(loop1 (##cte-parent-cte c)
r)))))
(env-ref (the-env) var-name))
~/test:$ cat test.scm
(define-macro (foo)
(define x 20)
(load "./lookup-var")
(pp `(foo ,(lookup-var 'x))))
(define-macro (bar)
(define x 20)
(include "./lookup-var.scm")
(pp `(bar ,(lookup-var 'x))))
(foo)
(bar)
~/test:$ gsi test.scm
(foo #!unbound)
(bar 20)
note that lookup-var is just a function ... i'm surprised that
load/include gives me different results
More information about the Gambit-list
mailing list