I’m a newbie prolog programmer, and for an assignment, I have to have a basic program that succeeds if and only if list X is a list of two elements, with the first as the same as the second.
From my view of prolog, programs seem to be pretty small, so I typed this in:
firstPair(x,x).
When I run it under swipl, I get this as output:
Syntax error: Operator expected
Is there something more that needs to be done? I thought that if I executed this with say, firstPair(1,2). this would be all it would need to know that it is false.
First, lowercase
xis not a variable, it’s an atom. Makexuppercase to fix the problem:Second, you do not type this into the interpreter. Rather, you write it into a file
firstPair.pl, and then read that file into Prolog.At the command prompt, type this:
Press enter. Now you can use your
firstPair/2rule.Finally, since the assignment talks about lists, I think the instructor wanted you to write
firstPair/1, notfirstPair/2: