3 ms·
Prolog lists are predicates, like pretty much everything else in the language. Lists have the functor '.' (the dot) and two arguments, a term and a list, so the
by YeGoblynQueenne 10y ago
Prolog lists are predicates, like pretty much everything else in the language. Lists have the functor '.' (the dot) and two arguments, a term and a list, so they're defined recursively.
Frex, this is a list:
.(a, .(b, .(c, .(d, []))))
'[]' is an atom that stands for the empty list.
Normally however we write lists like this:
[a,b,c,d]
Which is syntactic sugar used in the vast majority of Prolog code.
The easiest way to think of it is that a list is a pattern, consisting of two square brackets enclosing any number of terms. You can't really call functions on it, but you can pass it as an argument to other predicates, and match it to other patterns.