I'm trying to implement a predicate that works as follows:
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.
I need this functionality for a program, which has optionality a gui (XPCE) or not. You can call it with
start(true) % with gui
or
start(false) % without gui
Because I don't want to write two different predicates with the same logic, but one time with gui and another time without, I want to have one one predicate, that invokes the gui-code only if start(true) were invoked.
Thanks for your help!
The standard Prolog "if-statement" is:
where
If
,Then
, andElse
are goals. You can use if easily on the definition of your predicate to switch on the argument of the predicatestart/1
:When there's no
Else
goal, you can replace it with the goaltrue
. The goal(If -> Then)
fails when theIf
goal fails. I.e. the(If -> Then)
goal is equivalent to(If -> Then; fail)
, not to(If -> Then; true)
.