4.2 A propositional logic interpreter

This program to demonstrate the use of operators in Prolog.

  1. Logical connectives and, or, if and negation are defined as operators and given the same semantics as their Prolog counterparts.
  2. A small procedure play/0 is provided to allow the answers ’true’ and ’false’ to be supplied and
  3. there is a simple front end to present an interface for the user to interact with

The program starts automatically when the file is consulted and presents a prompt >. The user inputs a sentence in propositional logic and the program outputs its truth value and then re-presents the prompt. The program terminates when the user types stop..

?- [logic].  
% logic compiled 0.00 sec, 220 bytes  
 
Yes  
 
> p.  
true  
> q.  
true  
> r.  
false  
> p and q.  
true  
> p and r.  
false  
> p or r.  
true  
> r or p.  
true  
> p implies q.  
true  
> p implies r.  
false  
> r implies p.  
true  
> r implies r.  
true  
> p implies ~r.  
true  
> stop.  
goodbye  
 
yes