If statement Prolog if语句
我试图实现一个谓词,其工作原理如下:If statement Prolog if语句,if-statement,prolog,If Statement,Prolog,我试图实现一个谓词,其工作原理如下: 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
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
或
因为我不想用相同的逻辑编写两个不同的谓词,但一次使用gui,另一次不使用,我希望有一个谓词,只有在调用start(true)时才调用gui代码
谢谢你的帮助 标准序言“if语句”是:
其中,如果
,那么
和其他
是目标。您可以在谓词的定义上轻松地使用if打开谓词的参数start/1
:
pred :-
% common code
( start(true) ->
% gui-only code
; % non-gui code
),
% common code
当没有
Else
目标时,可以将其替换为目标true
。当If
目标失败时,目标(If->Then)
失败。也就是说,(If->Then)
目标相当于(If->Then;fail)
,而不是(If->Then;true)
,谢谢您的帮助!是的,我知道这个语法。但是如果我没有“%non-guy code”,比如(if->Then),我该怎么办呢!完美的非常感谢你,伙计!谢谢卡洛。我已经编辑了我的答案,以便更好地阐明这个控件构造的语义。
(If -> Then; Else)
pred :-
% common code
( start(true) ->
% gui-only code
; % non-gui code
),
% common code