I’m using: SWI-Prolog version (threaded, 64 bits, version 9.2.8)
My problem:
Based on exercise 4.5 of this tutorial I have implemented the listtrans(G, E) predicate which translates a list of German words to a list of English words.
My solution works fine for translations from G to E or vice versa, but does not give me the answer I want when I query G and E at the same time.
What I’m getting is:
?- listtran(G, E).
G = E, E = [] ;
G = [eins],
E = [one] ;
G = [eins, eins],
E = [one, one] ;
G = [eins, eins, eins],
E = [one, one, one] ;
G = [eins, eins, eins, eins],
E = [one, one, one, one]
Of course this is not wrong, but I would like to have something like
?- listtran(G, E).
G = E, E = [] ;
G = [eins],
E = [one];
G = [zwei],
E = [two];
...
G = [eins, eins],
E = [two, two];
and so on.
My code looks like this:
tran(eins,one).
tran(zwei,two).
tran(drei,three).
tran(vier,four).
tran(fuenf,five).
tran(sechs,six).
tran(sieben,seven).
tran(acht,eight).
tran(neun,nine).
listtran([], []).
listtran([X|R1], [Y|R2]) :- tran(X, Y), listtran(R1, R2).
My question:
How do I have to modify listtran, in order to get the desired behavior?
What I tried:
Currently I can modify my query using a helper predicate
samelen([], []).
samelen([_|R1], [_|R2]) :- samelen(R1, R2).
Now when I do the following query, I get the desired result:
?- samelen(X, Y), listtran(X, Y).
But, if possible, I would prefer to find a solution which does not need this helper in the query.