Well do you know what a predicate is, in logic?
https://en.wikipedia.org/wiki/Predicate_%28mathematical_logi...What this prolog code is doing is defining a predicate called “list_length“, which captures the relation between a list and the integer that represents the length of the list.
To do that you start with a base case, the relation between an empty list and the integer that represents the length of the list. That's the first prolog statement:
list_length([], 0).
It has no
Body so this
Head clause is always true: we are defining the
list_length predicate for [] and 0. (Another way of saying that is that the pair ([], 0) is in some set called list_length.)
The second statement has three Body clauses that specify three conditions:
1. You have an integer (technically a Natural number, not negative) named 'N' that is greater than zero. We do not care which integer it actually is at this point, just that it's greater than zero.
2. That integer 'N' is the sum of some other integer named 'N0' and one. We also do not care what 'N0' actually is, just that it is one less than 'N'.
3. There is some list named 'Ls', and the pair (Ls, N0) is in the set named 'list_length'. We also do not care what this list actually contains, just that it exists and that list_length(Ls, N0) is True.
Given the above three conditions are satified, Prolog can conclude:
4. The pair ([_|Ls], N) is in the set named 'list_length'.
You have to understand that the '_' mean anything, and '[foo|bar]' is how you add foo to the list bar to make a new longer list. (Like [1|[2|[3|[]]]] is the list 3 2 1.) See https://en.wikipedia.org/wiki/Cons#Lists
That code is enough information for the underlying Horn Clause Resolution to be able to do things like find the length of a list, or find lists of a given length. It's very powerful.
https://en.wikipedia.org/wiki/Horn_clause