Varun Gorantla
Varun Gorantla

Reputation: 129

Prolog syntax error operator expected

It says there's an error operator expected. I know this syntax error is in line 5 but I can't figure it out. I have highlighted that line with ** thx.

 action(X : Y,0 : Y):-X>0.
action(X : Y,X : 0):-Y>0.
action(X : Y,4:Y):-X<4. 
 action(X : Y,X : 3):-Y<3.
 **action(X : Y,4 : Z):- X<4, Z is Y−(4−X), Z>=0.**

 Path(X):- 
   path(0 : 0,[0 : 0],X).

Upvotes: 2

Views: 946

Answers (2)

lurker
lurker

Reputation: 58224

Prolog predicate names must begin with a lower case letter. So as @CapelliC points out, Path(X) :0-... is going to be a problem.

But your syntax error on line 5 is because you copy/pasted this code from something online or from an eBook perhaps. In your expression, Y−(4−X) those symbols are not minuses but something else that look like minuses (perhaps EM dashes). Try retyping line 5 manually, and the problem will go away.

This one is a problem:

Y−(4−X)

And this one is correct:

Y-(4-X)

There is actually a subtle difference in length of the dash you can see if you look closely. The second example is an actual dash or minus (ASCII code hex 2d). The first example of a dash is a special character (a hex dump shows a character code of 59 88 92). This is an issue with copy/pasting code from an eBook or other electronic document, since there are several characters used for visual convenience that aren't the specific one required by the language.

Upvotes: 2

CapelliC
CapelliC

Reputation: 60004

the error is the clause following

Path(X):-
 ...

should be

path(X):- 
 ...

Upvotes: 1

Related Questions