Razark
Razark

Reputation: 7

PROLOG-Syntax error: "." expected after the end of line although it is already present

:- dynamic (currentPlayer/1).
currentPlayer(ucup).    

printtest(X):-
currentPlayer(X),
format('Current player is: ~w\n', [X]),
retract(currentPlayer(X)),
assertz(currentPlayer(asep)).

I dont get why it keeps telling me there are syntax error, while last time i check my syntax is right. The error i got is :

syntax error: . or operator expected after expression
1 error(s)

and it this error leads to the first line. My expectation: if i run the printtest query (printtest(ucup)), it will prints out, but the second time, it change to no as the current player is now asep, so it should be printtest(asep) which would printout the text.

Upvotes: 0

Views: 42

Answers (1)

Paulo Moura
Paulo Moura

Reputation: 18663

The ISO Prolog standard, which GNU Prolog follows closely, doesn't require the atom dynamic to be declared as an operator. You get that error due to the space after dynamic. Write instead:

:- dynamic(currentPlayer/1).

Upvotes: 1

Related Questions