Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

“Syntax error: Operator expected” in Prolog

Tags:

prolog

I have this graph structure representing data flow in Prolog.

  • I have an edge from node 1 to 2, 1 to 3, etc.
  • Variable x is defined in node 1, variable t in node 4, etc.
  • Variable d is used in node 4, variable x in node 7, etc.

The function definition_clear_path should compute the definition-clear path of any variable.

When I run this I get the following error:

definition_clear_path/3: Undefined procedure: definition_clear_path1/4
         However, there are definitions for:
               definition_clear_path/3

When I enter the rule for definition_clear_path1 from the terminal I get Syntax error: Operator expected. Why?

edge(1, 2).
edge(1,3).
edge(3,7).
edge(3,4).
edge(4,6).
edge(4,5).
edge(7,x).
def(p,1).
def(e,1).
def(d,1).
def(x,1).
def(c,1).
def(d,4).
def(t,4).
def(c,5).
def(x, 6).
def(c,6).
use(d,3).
use(e,3).
use(d,4).
use(c,4).
use(x,4).
use(t,4).
use(c,5).
use(x,6).
use(c,6).
use(d,6).
use(x,7).
pos_path(X,Y, [X,Y]):- edge(X,Y).
pos_path(Start, End, [Start|T]) :- edge(Start,Mid), pos_path(Mid, End, T).


definition_clear_path( Node , J , Var ):- definition_clear_path1( Node , J , Var , [    Node ] ) .

definition_clear_path1(B , J, K , F):- edge (B , J ).

definition_clear_path1( Node , J , Var , L):- 
edge ( Node , N1 ) ,
not(def( Var , N1 )) ,
not(use( Var , N1 )) ,
definition_clear_path1( N1 , J , Var , [ Node | L ] ) .
like image 409
Lyes Khalil Avatar asked May 21 '11 15:05

Lyes Khalil


People also ask

How do you fix a syntax error in Prolog?

Remove the space between edge and the opening parenthesis. Spaces delimit terms, so Prolog will think that edge is an operator rather than the functor of a compound term.

How do you use not in Prolog?

Because of the problems of negation-as-failure, negation in Prolog is represented in modern Prolog interpreters using the symbol \+ , which is supposed to be a mnemonic for not provable with the \ standing for not and the + for provable.


1 Answers

Remove the space between edge and the opening parenthesis.

Spaces delimit terms, so Prolog will think that edge is an operator rather than the functor of a compound term.

like image 64
Nick Main Avatar answered Sep 28 '22 17:09

Nick Main