I have been trying to learn Prolog and came across this syntax on some example code.
solve(Hs) :- Hs = [_,_,_,_,_],
member(h(_, _, _, _, dog), Hs).
This is only a portion of the code, but I'm confused with the h(_,_,_,_,dog)
does.
Any help would be greatly appreciated!
All the underscores can match anything. It is a wild card. You are basically looking for a fact(?) with the last part equal to dog.
The underscores
_
just indicate that there is a value in that position, but we don't care about it.The first part effectively says that
Hs
is a 5 item list. The second part says that in that list ofHs
, one of the items is a compound termh/5
(h with 5 subterms) where the last is the atom,dog
.