如何检查/导出/序列化(狡猾的)Scheme 环境
我想在另一个 guile 进程中导出或复制方案环境。我想象的算法会做这样的事情来序列化:
(map (lambda (var val) (display (quasiquote (define ,var ,val))
(newline))
(get-current-environment))
然后我会在另一端读取/评估它。
然而,虽然有些函数可以返回当前环境,但它们采用某种内部格式,我无法映射
。怎样才能“行走”如上的环境呢?或者,我还能如何将环境复制到另一个进程中?
I'd like to export or replicate a scheme environment in another guile process. The algorithm I'm imagining would do something like this to serialize:
(map (lambda (var val) (display (quasiquote (define ,var ,val))
(newline))
(get-current-environment))
And then I'd read/eval that on the other end.
However, while there are functions that return the current environment, they are in some internal format that I can't just map
across. How can I "walk" the environment as the above? Alternatively, how else can I replicate an environment into another process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以像这样分解所谓的“当前环境”:
并且你可以调用 (get-current-binding-list) 来获取当前模块中的变量绑定列表。
请注意,此列表中的每个元素都是一对符号和变量类型,例如(符号名称.变量类型)。所以你可以这样打印:
例如,你有一个 var 绑定:
然后:
==>
#<变量 9bb5108 值:5>
这个结果是变量“abc”的“变量类型”。您可以使用variable-ref 过程获取它的值。
因此,您可以跟踪所有绑定并在代码中执行某些操作,只需打印 var-name 和 var-value 即可。
我知道我的回答太简短,但我认为有足够的信息可以帮助您在手册中找到更多详细信息。
希望这会对您有所帮助。
you may decompose the so-called "current-environment" like this:
and you can call (get-current-binding-list) to get variables binding list in current-module.
Please note that each element in this list is a pair of symbol and variable type, say, (symbol-name . variable-type). So you may print it like this:
for a instance ,you got a var binding:
then:
==>
#<variable 9bb5108 value: 5>
This result is a "variable type" of variable "abc". You can get it's value with variable-ref procedure.
So you can trace all the bindings and do something ,in your code ,it's simply print var-name and var-value.
I know my answer is too brief, but I think there's enough information to help you to find more details in the manual.
Hope this will help you.
你不能真正序列化Scheme环境。我什至不知道是否可以(可移植地)序列化延续。哦,别忘了 FFI。端口和线程也是不可序列化的。
You can't really serialize Scheme environment. I don't known even it's possible to (portably) serialize continuations. Oh, and don't forget about FFIs. Ports and threads are unserializable too.