print customized result in prolog

Posted by Allan Jiang on Stack Overflow See other posts from Stack Overflow or by Allan Jiang
Published on 2012-10-14T19:19:10Z Indexed on 2012/10/14 21:37 UTC
Read the original article Hit count: 294

Filed under:
|


I am working on a simple prolog program. Here is my problem.

Say I already have a fact fruit(apple).

I want the program take a input like this ?- input([what,is,apple]).

and output apple is a fruit

and for input like ?-input([is,apple,a,fruit])
instead of default print true or false, I want the program print some better phrase like yes and no

Can someone help me with this?

My code part is below:

input(Text) :-
phrase(sentence(S), Text), 
perform(S).
%...
sentence(query(Q))     --> query(Q).

query(Query) --> 
['is', Thing, 'a', Category],
{ Query =.. [Category, Thing]}.

% here it will print true/false, is there a way in prolog to have it print yes/no, 
%like in other language: if(q){write("yes")}else{write("no")}
perform(query(Q))     :- Q.   

© Stack Overflow or respective owner

Related posts about prolog

Related posts about swi-prolog