Re: Tracing with out using trace?
- From: Markus Triska <triska@xxxxxx>
- Date: Sun, 03 Sep 2006 13:56:41 +0200
Bruce Horrocks <news@xxxxxxxxxxxxxxxxx> writes:
Or friend-of-friend where there could be any number of connections
before getting to a final person?
What about it? A list can hold any number of connections. Example
fact base and rules for (transitive) friend-of-friend:
friend(mary, harry).
friend(harry, sally).
friend(sally, garry).
friend(harry, mary).
friend(garry, sally).
friend_of_a_friend([A,B|Rest]) :-
friend(A, B),
friend_of_a_friend(B, Rest, [A,B]).
friend_of_a_friend(A, [B], Visited) :-
friend(A, B),
\+ memberchk(B, Visited).
friend_of_a_friend(A, [B|Rest], Visited) :-
friend(A, B),
\+ memberchk(B, Visited),
friend_of_a_friend(B, Rest, [B|Visited]).
Yielding:
?- friend_of_a_friend(Fs).
Fs = [mary, harry, sally] ;
Fs = [mary, harry, sally, garry] ;
Fs = [harry, sally, garry] ;
It's easy to derive the corresponding binary relation.
All the best,
-- Markus Triska
.
- Follow-Ups:
- Re: Tracing with out using trace?
- From: Bruce Horrocks
- Re: Tracing with out using trace?
- References:
- Tracing with out using trace?
- From: Bruce Horrocks
- Re: Tracing with out using trace?
- From: Markus Triska
- Re: Tracing with out using trace?
- From: Bruce Horrocks
- Tracing with out using trace?
- Prev by Date: Re: Tracing with out using trace?
- Next by Date: Re: Tracing with out using trace?
- Previous by thread: Re: Tracing with out using trace?
- Next by thread: Re: Tracing with out using trace?
- Index(es):