0

I'm relatively new to Prolog and my aim from this code is to try and find all routes between all defined edges. Prolog should output me the full route from the inputted start to destination. However I keep getting an error bash: -c: line 1: syntax error near unexpected token ('

I was wondering if im going about this in the right way? or maybe I'm being blind to silly mistakes..

Here is my code.

edge(o,p1).
edge(p1,k).
edge(k,l).
edge(l,c).
edge(c,b).
edge(c,w).
edge(c,m).
edge(l,p2).


path(X,Y,Path) :- path(X,Y,[X],Q), reverse(Q,Path).


path(X,Y,Visited,[Y|Visited]) :- edge(X,Y).
path(X,Y,Visited,Path) :-
    edge(X,Z),
    Z \== Y,
    \+ member(Z,Visited),
    path(Z,Y,[Z|Visited],Path).

The TEST CASE I was trying to run was

path(o, m, Path).

edit: i ran it with swipl and these errors were returned image here, it didnt let me upload an image sorry

  • What command are you using to try and execute this? What queries do you plan on using to test your code? – Scott Hunter Mar 06 '23 at 13:24
  • @ScottHunter Edited & added test case in post – Elephants unite Mar 06 '23 at 13:25
  • What command are you using to try and execute this? – Scott Hunter Mar 06 '23 at 13:53
  • I copied this verbatim, used your query and got `Path = [o, p1, k, l, c, m] ; false.` – TA_intern Mar 06 '23 at 15:41
  • Say `?- path(edge, Path, o, m).` with [this definition](https://stackoverflow.com/q/30328433/772868). – false Mar 06 '23 at 19:26
  • Your error suggests you are trying to run it as a Linux shell script like `./paths.pl` and Bash is trying to interpret it. You need to run it through `swipl` somehow or other - see https://www.swi-prolog.org/pldoc/man?section=plscript and https://stackoverflow.com/questions/25467090/how-to-run-swi-prolog-from-the-command-line for some options – TessellatingHeckler Mar 07 '23 at 04:59

0 Answers0