Your last query, ?- member('Course',relation2(relation(X,_)))
isn't succeeding because the second argument of member is a predicate rather than a list. To get a clear understanding of what's going on, you can write a predicate in your file like this:
test('Course', relation2(relation(X,_)).
and then query test/2
with free variables, ?- test(X,Y)
, and observe the values of X
and Y
. That's those values are exactly what member/2
is getting, but it is only defined to tell us things about lists.
In order to pass the list in the first argument of relation/2
to member/2
, you have to first instantiate X
by calling the predicate and then call member/2
with the instantiated X
as an argument:
?- relation2(relation(X,_)), member('Course', X).
Note that the second argument of relation/2
is a list of lists, so in order to check for members therein, you'll have to use a list as your first argument of member/2
, e.g.,
?- relation2(relation(_,X)), member([CourseName, _,_], X).
will be true if CourseName matches the first element of the lists.