user3738728
user3738728

Reputation: 1

Prolog Instantiation Error Issue

I've been getting an instantiation error in some prolog code I'm working on.

uncaught exception: error(instantiation_error,(is)/2)

the error occurs when a predicate called connects calls linked to (hopefully) produce a list of children that are linked to a node (called Next).

I've tested linked and it seems to work fine on it's own it's just when it is called like this. I'm guessing it has something to do with the 'child' but I'm new to prolog so I'm not sure what exactly.

I have a second version of linked which works fine with connects but doesn't actually work by itself.

here is some of the code:

linked(loc(A, B), loc(C, D)) :- C is A+1, D is B+1.
linked(loc(A, B), loc(C, D)) :- C is A-1, D is B-1.
linked(loc(A, B), loc(C, D)) :- C is A, D is B-1.
linked(loc(A, B), loc(C, D)) :- C is A, D is B+1.
linked(loc(A, B), loc(C, D)) :- C is A-1, D is B.
linked(loc(A, B), loc(C, D)) :- C is A+1, D is B.

connects(State, End, Colour, Next, Close) :- linked(Child, Next)

There is more to the program than this but through much debugging I have come to the conclusion that these lines are where the problems are occurring.

More info: Connects is a predicate that is used in a predicate called connected that works out whether there is an unbroken path of same elements. Linked is a predicate that finds out if two nodes are next to each other (vertical, diagonal, horizontal. not in a square grid though, think hexagons).

here is an example state too

    [e,e,b,e,e],
   [e,w,w,b,e],
  [b,w,b,w,w],
 [w,w,b,b,b],
[e,e,b,w,e]

Upvotes: 0

Views: 4152

Answers (1)

danielp
danielp

Reputation: 1187

The error is yield because there is a variable on the right side of an is.

In connects/5 you use linked(Child,Next), but Child is nowhere else used, so always unbound. So when linked/2 is called, A and B are always variables which results in the error.

Do you mean linked(State,Next)?

Upvotes: 1

Related Questions