I have something like this in the database.
flight( tk1, ist, esb, 40 ).
flight( tk2, ist, mlx, 90 ).
And I have written a predicate called test.
test([S], L1):-
findall( C, (flight( _, S, C, _ )), L1 ).
The output when I write test([ist], X). is X = [esb, mlx]. So this is true but when I write test(X, [esb, mlx]). it is false. Why is it false? Should I write another predicate for this?
Well, as you can see,
findall/3isn’t necessarily supposed to be used with a bound last parameter, for example in SWI-Prolog, in its description we can read:which indicates that
Bagmust be free when called. Some predicates sadly don’t work in all possible ways!Though, you can easily write another predicate to test that:
BTW, since your relation is clearly not a bijection between
SsandCs, you shouldn’t expect the result to be reverses (test(A, R), reverse_test(R, A2)won’t result inA == A2)