考虑这个 Prolog 谓词:
silly:-
1 = 1.
silly:-
1 = 2.
查询时,输出答案有两种状态:true 和 false。无论如何,有没有办法要求 Prolog 在析取中遇到 true 语句时立即终止?
问题是 ”无论如何,有没有办法要求 Prolog 在析取中遇到真实语句时立即终止"?
答案是 ”Use once/1
当询问答案时".
例如:
?- [user] .
silly:-
1=1 .
silly:-
1=2 .
silly:-
2=2 .
end_of_file .
?- %% query WITHOUT once {results in 2 answers} : %%
silly .
true ;
true.
?- %% query WITH once {results in 1 answer} : %%
once(silly) .
true.
剪切的使用!
不符合所述问题的语义要求。
Using cut would be appropriate if the question had been more like "Is there anyway to ask tell Prolog to terminate as soon as it hits a true statement** a statement specially indicated* in a disjunction" ?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)