Howto append to a list recursively
Howto append to a list recursively
(OP)
I am trying to write a prolog snippet which will find the relations between entities. I have this:
related(a,b,ab).
related(b,c,bc).
related(c,d,cd).
relation(X,Y,Z):-related(X,A,G),related(A,Y,H),Z=[G,H].
When I ask
relation(X,Y,Z).
The answer I'm after is:
X=a, Y=b, Z=ab
X=b, Y=c, Z=bc
etc. for the trivial cases and then:
X=a, Y=c, Z=[ab,bc]
X=b, Y=d, Z=[bc,cd]
X=a, Y=D, Z=[ab,bc,cd]
Is there a kind soul who could help me out?
Thanks in advance.
related(a,b,ab).
related(b,c,bc).
related(c,d,cd).
relation(X,Y,Z):-related(X,A,G),related(A,Y,H),Z=[G,H].
When I ask
relation(X,Y,Z).
The answer I'm after is:
X=a, Y=b, Z=ab
X=b, Y=c, Z=bc
etc. for the trivial cases and then:
X=a, Y=c, Z=[ab,bc]
X=b, Y=d, Z=[bc,cd]
X=a, Y=D, Z=[ab,bc,cd]
Is there a kind soul who could help me out?
Thanks in advance.




