user425243
user425243

Reputation:

Error in prolog

lookup([(X,A)|_],X,A).      
lookup([_|L],X,A) :- lookup(L,X,A).

hi(_,t,bool).      
hi(_,f,bool).
hi(g,var(X),Y) :- lookup(g,X,Y).
hi(_,in(X),int).
hi(_,fl(X),real_exp).
hi(g,plus(A,B),int) :- hi(g,A,int),hi(g,B,int),!.  

I have the above line of code in Prolog which basically checks the type of a plus operation.

so when I have the following Query at the terminal:

hi([],plus(in(1),in(2)),T).  

I get the answer as false instead of T = int.

what could be the correct line of code in my program ? I am unable to sort out the error !!!!

Upvotes: 0

Views: 198

Answers (2)

hardmath
hardmath

Reputation: 8823

You used an atom g in the rule for hi/3 where you probably meant to use a variable G.

Upvotes: 1

thanos
thanos

Reputation: 5858

the plus rule is: hi(g,plus(A,B),int) :- hi(g,A,int),hi(g,B,int),!.

while you call: hi([],plus(in(1),in(2)),T).

not sure what do you want to do with g and [] (some token list perhaps?) but it looks like you have to either change the query or the rule (or and one more rule). maybe g was supposed to be a variable G? cant really tell xd

Upvotes: 0

Related Questions