Question: I am trying to write an SWI Prolog program to argue with yourself. The program should take statements that are typed in as a list

I am trying to write an SWI Prolog program to argue with yourself. The program should take statements that are typed in as a list and change the pronouns and negate them. For instance, you should change you to I, are should change to am not, and so on. Here is a possible sample session:

?- argue([you,are,a,stupid,computer],X).

X=[i,am,not,a,stupid,computer]

Yes

?- argue([you,are],Y).

Y=[i,am,not]

Yes

?-argue([are],Z).

Z=[am,not]

Yes

?-

My current program is having some slight issues and I am not sure what is wrong with it. See my program below. Any help is greatly appreciated!

% argue prolog program

argue([],[]).

argue(X,Y):-

member('i',X), replace(X,'i','you',Y); member('am',X), replace(X,'you','i',Y); member('am',X), replace(X,'am','arent',Y); member('are',X), replace(X,'are','am not',Y); member('is',X), replace(X,'is','isnt',Y); member('isnt',X), replace(X,'isnt','is',Y); member('your',X), replace(X,'your','my',Y); member('my',X), replace(X,'my','your',Y); member('does',X), replace(X,'does','doesnt',Y); member('doesnt',X), replace(X,'doesnt','does',Y). 

% Helper Function

replace([],,,[]).

replace([X|Y],X,A,[A|Z]):-!,

replace(Y,X,A,Z). 

replace([X|Y],A,B,[X|Z]):-!,

replace(Y,A,B,Z).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!