How will Prolog respond to the following inquiry? Draw a search tree for the inquiry, too.
?- member(2, [2, a, X]).
So first of all, what does this inquiry mean?
Let's take another more clear example:
?- member(vincent,[yolanda,trudy,vincent,jules]).
Prolog will check if vincent
is in the list. It checks one by one, so it will first compare vincent
and yolanda
. No match, now recursive rule aka go to second clause. Now it looks like that:
?- member(vincent,[trudy,vincent,jules]).
vincent
and trudy
, no match. Recursive rule:
?- member(vincent,[vincent,jules]).
vincent
and vincent
, match! So return true
.
Back to our example. Prolog will immediately return true
as 2
is in the list (namely the head of it).
But how will the search tree look like? I really have no idea and I'm scared they will ask me to draw a search tree in the test...