[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
PrologAssume
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
PrologAssume
(Prolog) assume
A set of clauses I (that is, Bilderbikkel) use for debugging.
% If the user enters a number from 1 to an including 3
% the right clauses are called.
% then the input '2' would results in calling both action(2) and action(X)
%
%
%
% Note that you can remove 'nondeterm' from the action's predicate,
% but I left it in, so you do can comment out the cuts
PREDICATES
assumeEqual(integer, integer)
assumeEqual(integer, integer, string)
assumeUnequal(integer, integer)
assumeUnequal(integer, integer, string)
nondeterm action(integer)
CLAUSES
assumeEqual(X,Y) :-
X=Y,
!.
assumeEqual(X,Y) :-
X<>Y,
!,
write("Condition X=Y for X=",X, " and Y=",Y," failed!"),
exit(1).
assumeEqual(X,Y,_) :-
X=Y,
!.
assumeEqual(X,Y,DebugMessage) :-
X<>Y,
!,
write("Condition X=Y for X=",X, " and Y=",Y," failed!"),
nl,
write("Debug message: ", DebugMessage),
exit(1).
assumeUnequal(X,Y) :-
X<>Y,
!.
assumeUnequal(X,Y) :-
X=Y,
!,
write("Condition X<>Y for X=",X, " and Y=",Y," failed!"),
exit(1).
assumeUnequal(X,Y,_) :-
X<>Y,
!.
assumeUnequal(X,Y,DebugMessage) :-
X=Y,
!,
write("Condition X<>Y for X=",X, " and Y=",Y," failed!"),
nl,
write("Debug message: ", DebugMessage),
exit(1).
action(1) :-
% !, % Cut removed on purpose
nl,
write("You typed one").
action(2) :-
% !, % Cut removed on purpose
nl,
write("You typed two").
action(3) :-
% !, % Cut removed on purpose
nl,
write("You typed three").
action(X) :-
assumeUnequal(X,1,"action(X)"),
assumeUnequal(X,2,"action(X)"),
assumeUnequal(X,3,"action(X)"),
!,
nl,
write("You typed an unknown number").
GOAL
write("Type a number from 1 to 3: "),
readInt(Num),
action(Num),
nl.
Code links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
