我正在尝试实现一个按如下方式工作的谓词:
pred :-
% do this always
% if-statement
%do this only, when if-statement is true
% do this also always, independent if if-statement where true or false.
我需要一个程序的此功能,该程序具有 gui (XPCE) 或不具有可选性。你可以用以下方式调用它
start(true) % with gui
or
start(false) % without gui
因为我不想用相同的逻辑编写两个不同的谓词,但一次使用 gui,另一次不使用,我想要一一谓词,仅当调用 start(true) 时才调用 gui 代码。
感谢您的帮助!
标准 Prolog“if 语句”是:
(If -> Then; Else)
where If
, Then
, and Else
是目标。您可以在谓词的定义上轻松使用 if 来打开谓词的参数start/1
:
pred :-
% common code
( start(true) ->
% gui-only code
; % non-gui code
),
% common code
当没有Else
goal,您可以将其替换为目标true
。目标(If -> Then)
失败时If
目标失败。 IE。这(If -> Then)
目标相当于(If -> Then; fail)
,不(If -> Then; true)
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)