8
votes

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 ] ) .
1
If you put definition_clear_path at the end, does the error goes away? - George Kastrinis

1 Answers

16
votes

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.