468,296 Members | 1,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,296 developers. It's quick & easy.

Display results in Prolog

if twol then twolegs.
if twoh then twohands
if tenf then tenfingers.
if twof then twofeets.
if smallh then smallhair.
if fourlegs and nohands and nofingers and fourfeets and doghair then dog.
if twolegs and twohands and tenfingers and twofeets and smallhair then person.
if fourlegs and nohands and nofingers and fourfeets and doghair then dog.
if twolegs and twohands and tenfingers and twofeets and smallhair then person.


% forward chaining
forward :-
new_derived_fact(P),!,
write('solution: '),writeln(P),
assert(derived_fact(P)),
forward ;
writeln('No more facts').
new_derived_fact(P) :-
if Cond then P,
\+ fact(P),
\+ derived_fact(P),
truth(Cond).
truth(P) :-
fact(P) ;
derived_fact(P).
truth(P1 and P2) :-
truth(P1),
truth(P2).
truth(P1 or P2) :-
truth(P1) ;
truth(P2).

%database
solution(person, addressx, idp1, house).
solution(person, addressy, idp2, house).
solution(person, addressz, idp3, house).
solution(dog, dogaddressx, dogid1, doghouse).
solution(dog, dogaddressy, dogid2, doghouse).

I have this code in prolog using forward chaining. How to display the result "person" like "address, id, house" from datababase??
Apr 24 '20 #1
0 1442

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by XML newbie: Urgent pls help! | last post: by
1 post views Thread by XML newbie: Urgent pls help! | last post: by
1 post views Thread by aziziahmad | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.