What does this syntax mean? (Prolog)
12,122
Solution 1
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 of Hs
, one of the items is a compound term h/5
(h with 5 subterms) where the last is the atom, dog
.
Solution 2
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.
Author by
Ryan
Updated on June 04, 2022Comments
-
Ryan almost 2 years
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!