Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I get what you're trying to say, that in Prolog you are able to lookup structures by their shape, and not by some pre-defined path, as in other languages, so you can do both `edge(1, A)` and `edge(A, 1)`.

But the graph in your example is still directed, simply by the virtue of predicate arguments being ordered.

So your example misses two rules to be correct.

  reachable(V, W) :- edge(V, W).
  reachable(V, W) :- edge(W, V).
  reachable(V, W) :-
    reachable(V, U),
    reachable(U, W).
Alternatively you could introduce

  edge(V, W) :- edge(W, V).


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: