How to impelement correspond function in prolog

Viewed 426

I am a beginner of Prolog and I'd like to know how to implement this correspond function.

correspond(E1, L1, E2, L2)

this holds when in one place where list L1 has the value E1, L2 has E2. This must work in any mode in which L1 and L2 are proper lists (that is, either [] or a list whose tail is a proper list). For example:

correspond(e,[h,e,l,l,o],X,[1,2,3,4,5])

should have only the solution X = 2.

Here is what I have tried by now:

 correspond(E1, L1, E2, L2).
 correspond(E1,[Elt1|List1],E2,[Elt2|List2]) :-
     nth0(Index, [Elt1|List1], E1).
     nth0(Index, [Elt2|List2], E2). 

I wanted to use Index as intermediate to get the value of E1 or E2, but these code returns either True or False.

1 Answers
Related