[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
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



last edited (October 25, 2006) by bilderbikkel, Number of views: 532, Current Rev: 1

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.