4 ms·
I guess, the point was, if list is a built-in construct, the function length should be also built in. (Unless, that is, natural numbers are defined in the stand
by Koshkin 10y ago
I guess, the point was, if list is a built-in construct, the function length should be also built in. (Unless, that is, natural numbers are defined in the standard library.)
- YeGoblynQueenne 10y agoProlog 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.
- tom_mellior 10y ago> I guess, the point was, if list is a built-in construct, the function length should be also built in. It is built in. No need to write your own length predicate. The quoted example is an illustration of a possible implementation. (Cue boring discussion of "built in" vs. "defined in the standard library".)
- vidarh 10y agoThat something is "built in" doesn't mean it won't be defined somewhere, such as in the standard library.