在prolog Systems跨系统的ATOM_TO_TERM/3等于什么?

发布于 2025-01-21 17:31:58 字数 571 浏览 0 评论 0原文

我发现Swi-Prolog提供了:

atom_to_term(+atom,-term,-bindings)
使用ATOM用作read_term/2使用选项variable_names
的输入 并在绑定中返回术语和变量绑定。
https://www.sw.sw-swi-prolog.org.org.org/pldoc/pldoc/man? predicate = atom_to_term/3

但是我很难弄清楚其他prolog Systems 在这方面提供。也许有些人确实已经获得了解决方案, 他们可能想分享吗?

示例它的作用:

?- atom_to_term('X + Y', T, N).
T = _A+_B,
N = ['X'=_A, 'Y'=_B].

I find that SWI-Prolog offers:

atom_to_term(+Atom, -Term, -Bindings)
Use Atom as input to read_term/2 using the option variable_names
and return the read term in Term and the variable bindings in Bindings.
https://www.swi-prolog.org/pldoc/man?predicate=atom_to_term/3

But I am having a hard time, figuring out what other Prolog systems
offer in this respect . Maybe some people did already obtain solutions,
that they might want to share?

Example what it does:

?- atom_to_term('X + Y', T, N).
T = _A+_B,
N = ['X'=_A, 'Y'=_B].

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

格子衫的從容 2025-01-28 17:31:58

两者 swi and 和 eclipse 支持term_string/3atom_string/atom_string/atom_string/2 ,您可以通过其中写入

atom_to_term(A, T, N) :-
    atom_string(A, S),
    term_string(T, S, [variable_names(N)]).

畸形字符串(语法错误)悄悄地失败,使用

atom_to_term(A, T, N) :-
    atom_string(A, S),
    term_string(T, S, [variable_names(N), syntax_errors(quiet)]).

其他错误处理选项为fail> fail(打印语法错误消息和失败)和错误(投掷错误/2项)。

Both SWI and ECLiPSe support term_string/3 and atom_string/2, with which you can write

atom_to_term(A, T, N) :-
    atom_string(A, S),
    term_string(T, S, [variable_names(N)]).

To make it quietly fail for malformed strings (syntax errors), use

atom_to_term(A, T, N) :-
    atom_string(A, S),
    term_string(T, S, [variable_names(N), syntax_errors(quiet)]).

Other error handling options are fail (print syntax error message and fail) and error (throw error/2 term).

动听の歌 2025-01-28 17:31:58

logTalk在所有这些后端prolystemp上运行,还有几个,提供了便携式 库在/到原子,字符(字符列表)和代码(字符代码列表)中实现阅读/写作术语。例如,使用GNU Prolog:

$ gplgt
...
| ?- {term_io(loader)}.
...
% (0 warnings)

(202 ms) yes
| ?- term_io::read_term_from_atom('X + Y', Term, [variable_names(Vars)]).

Term = A+B
Vars = ['X'=A,'Y'=B]

yes

原子结束时的一个时期是可选的:

| ?- term_io::read_term_from_atom('a(X, Y).', Term, [variable_names(Vars)]).

Term = a(A,B)
Vars = ['X'=A,'Y'=B]

(1 ms) yes

Logtalk, which runs on all those backend Prolog systems and several more, provides a portable term_io library that implements reading/writing terms from/to atoms, chars (lists of characters), and codes (lists of character codes). For example using GNU Prolog:

$ gplgt
...
| ?- {term_io(loader)}.
...
% (0 warnings)

(202 ms) yes
| ?- term_io::read_term_from_atom('X + Y', Term, [variable_names(Vars)]).

Term = A+B
Vars = ['X'=A,'Y'=B]

yes

A period at the end of the atom is optional:

| ?- term_io::read_term_from_atom('a(X, Y).', Term, [variable_names(Vars)]).

Term = a(A,B)
Vars = ['X'=A,'Y'=B]

(1 ms) yes
物价感观 2025-01-28 17:31:58

好的,我已经为GNU Prolog找到了这可以起作用:

atom_to_term(A, T, N) :-
   atom_concat(A, ' .', B),
   read_term_from_atom(B, T, [variable_names(N)]).

示例通过了:

?- atom_to_term('X + Y', T, N).
N = ['X'=A,'Y'=B]
T = A+B

但是Tau Prolog(浏览器),Scryer Prolog,Sicstus Prolog,Eclipse Prolog等呢?

Ok, I already found for GNU Prolog, that this could work:

atom_to_term(A, T, N) :-
   atom_concat(A, ' .', B),
   read_term_from_atom(B, T, [variable_names(N)]).

The example passes:

?- atom_to_term('X + Y', T, N).
N = ['X'=A,'Y'=B]
T = A+B

But what about Tau Prolog (Browser), Scryer Prolog, SICStus Prolog, ECLiPSe Prolog etc..?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文