如何在 SICStus Prolog 中模拟 SWI-Prolog 的 atom_to_term(+Atom, -Term, -Bindings)? [英] How to simulate atom_to_term(+Atom, -Term, -Bindings) of SWI-Prolog in SICStus Prolog?
本文介绍了如何在 SICStus Prolog 中模拟 SWI-Prolog 的 atom_to_term(+Atom, -Term, -Bindings)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 SICStus Prolog 编写 Dali 代理,我需要将原子转换为术语,但我无法使用 SWI-Prolog 中内置的 atom_to_term
I am using SICStus Prolog to write a Dali agent and I need to convert an atom to a term but I can't use atom_to_term
which is built in in SWI-Prolog
推荐答案
使用 library(codesio)
:
| ?- use_module(library(codesio)).
yes
?- set_prolog_flag(double_quotes,codes).
true.
| ?- read_from_codes("a(X,Y).",T).
T = a(_A,_B) ? yes
| ?- read_term_from_codes("a(X,Y).",T,[variable_names(VN_list)]).
T = a(_A,_B),
VN_list = ['X'=_A,'Y'=_B] ?
除此之外,您还需要 atom_codes/2
即 ISO.
In addition to that, you need atom_codes/2
which is ISO.
对于更复杂的操作,您可以使用 open_codes_stream/2
打开一个流.需要用 close/1
关闭.
For more complex operations, you can open a stream with open_codes_stream/2
. Which needs to be closed with close/1
.
这篇关于如何在 SICStus Prolog 中模拟 SWI-Prolog 的 atom_to_term(+Atom, -Term, -Bindings)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文