Suppose I have two arbitrary lists that represent the first two elements of a three-dimensional predicate:
[anna,berta,charlotte],[charles,bob,andy]
I want to map each element in the third list (the third element of a three-dimensional predicate) as follows:
[[anna,andy],[berta,bob],[charlotte,charles]]
Basically, the elements are selected sequentially in different ways. To match the elements sequentially, I developed the following code:
match([],[],[]). match([A|At],[C|Ct],[[A,C]|Dt]):-match(At,Ct,Dt).
But that would give me the following:
match([anna,berta,charlotte],[charles,bob,andy],X). X=[[anna,charles],[berta,bob],[charlotte,andy]]
So I need to somehow cancel the second list. So far, I have changed the code as follows:
match([],[],[]). match([A|At],[C|Ct],[[A,B]|Dt]):-reverse([C|Ct],[B|Bt]),match(At,Bt,Dt).
But this will constantly change the second list with each pass. The result will look like this:
match([anna,berta,charlotte],[charles,bob,andy],X). X=[[anna,andy],[berta,charles],[charlotte,bob]]
Question: How to cancel the second list only once, so the actual results correspond to the desired ones? Or is my approach fundamentally flawed? I'm new to the prologue and am currently stunned by this. Any help would be appreciated.