Reputation: 168
i am a beginner and use swi-Prolog. Can someone tell me why this piece of code doesn't work?
inp:- write('Enter the string'),nl,read(X),write(X).
abc:- subtract(X,['at','in','to','of'],L),write(L).
I keep getting the Singleton Variable[X] error. Thanks.
Upvotes: 1
Views: 767
Reputation: 7209
X in inp
predicate and X in abc
predicate - are totally different variables, not connected in any way.
You probably want something like this:
inp(X) :- write('Enter the string'),nl,read(X),write(X).
abc(X) :- subtract(X,['at','in','to','of'],L),write(L).
And then use it like inp(X), abc(X)
.
Upvotes: 2