本文介绍了序言:“香草"带有内置的元解释器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Jan Burse 的这个答案展示了 Prolog 中元解释器的最简单实现之一:
This answer by Jan Burse shows one of the simplest implementations of a metainterpreter in Prolog:
solve(true) :- !.
solve((A,B)) :- !, solve(A), solve(B).
solve(H) :- clause(H,B), solve(B).
我想扩展这个解释器,以便它可以调用内置函数.普通版本无法处理诸如 solve(member(X, [1,2,3,4]))
之类的调用.这可能使用 ISO 谓词吗?如果没有,是否可以使用 SWI-Prolog 谓词?
I would like to extend this interpreter so that it can call builtins. The vanilla one isn't able to handle calls such as solve(member(X, [1,2,3,4]))
. Is this possible using ISO predicates? If not, is it possible using SWI-Prolog predicates?
推荐答案
Stackoverflow 拒绝接受我的回答 :) 那是
Stackoverflow is refusing to accept my answer :) that was
打电话给他们/1个
编辑
例如
?- [user].
solve(true) :- !.
|: solve((A,B)) :- !, solve(A), solve(B).
|: solve(H) :- clause(H,B), solve(B).
|: solve(T) :- call(T).
|: ^Dtrue.
?- solve(member(X, [1,2,3,4])).
X = 1 ;
X = 2 ;
X = 3 ;
X = 4.
唯一的补充:solve(T) :- call(T)
.
这篇关于序言:“香草"带有内置的元解释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!