What is the meaning of predicate “simple/1” in Prolog (SWI-Prolog)

狂风中的少年 提交于 2020-01-17 08:31:16

问题


I run into problem while reading a book. I see a program use predicate "simple" ( I guess simple/1 ). I don't know what is the meaning of this predicate, I can't find it with ?-help(simple) in the console. But when I tried with some queries in console, it worked something like:

5 ?- simple(p(x)).
false.

6 ?- simple(mia).
true.

7 ?- simple(Mia).
true.

8 ?- simple(f(Mia)).
false.

I guess it is some sort of predicate to determine if the argument was Terms(or Variables) or Complex Terms.


回答1:


The swi-prolog manual has the following definition:

simple(@Term) is semidet Term is atomic or a variable.

the definition is in the quintus prolog compatibility library; in the quintus prolog documentation the definition is:

simple(+Term)

Term is currently instantiated to either an atom, a number, a database or a variable.

in any case, simple/1 is true if the argument is a simple term (not sure what the quintus manuals means by database; possibly a handler for an ODBC connection i guess)




回答2:


translated to ISO predicates:

simple(T) :- var(T) ; atomic(T).

var/1 it's the most basic metaprogramming device, because it's impossible to predicate (i.e. execute code, binding variables) about any clause without instancing the variables, that are many times the essential part we are interested to.



来源:https://stackoverflow.com/questions/9042879/what-is-the-meaning-of-predicate-simple-1-in-prolog-swi-prolog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!