Say I have the following piece of code:
edge(a, b).
edge(a, c).
edge(a, d).
Now when I do
neighbors(V, N) :- edge(V, N), writeln(N), fail.
I can get a list of the neighbors printed out to the console. But how can I get it as a result list? Something like
neighbors(V, Vs) :-
edge(V, N),
not(member(N, Vs)),
neighbors(V, [N|Vs]).
(the above piece doesn't really work due to the way member
is handled. Any suggestion please?