您可以像这样分解所谓的“当前环境”:
(define (get-current-binding-list)
(let* ((e (current-module)) ;; assume checking current-module
(h (struct-ref e 0)) ;; index 0 is current vars hashtable
)
(hash-map->list cons h) ;; return a vars binding list
))
您可以调用 (get-current-binding-list) 来获取当前模块中的变量绑定列表。请注意,此列表中的每个元素都是一对符号和变量类型,例如 (symbol-name . variable-type)。所以你可以像这样打印它:例如,你有一个 var 绑定:
(define abc 5)
然后:
(let ((vl (get-current-binding-list)))
(assoc-ref vl 'abc)
)
==>#<variable 9bb5108 value: 5>
这个结果是变量“abc”的“变量类型”。您可以通过 variable-ref 过程获得它的值。
所以你可以追踪所有的绑定并做一些事情,在你的代码中,它只是打印 var-name 和 var-value。
我知道我的回答太简短,但我认为有足够的信息可以帮助您在手册中找到更多详细信息。希望这会帮助你。