Availability:built-in

**length**(

`?List, ?Int`)

`Int`represents the number of elements in

`List`. This predicate is a true relation and can be used to find the length of a list or produce a list (holding variables) of length

`Int`. The predicate is non-deterministic, producing lists of increasing length if

`List`is a

*partial list*and

`Int`is unbound. It raises errors if

`Int`is bound to a non-integer.`Int`is a negative integer.`List`is neither a list nor a partial list. This error condition includes cyclic lists.^{126ISO demands failure here. We think an error is more appropriate.}

This predicate fails if the tail of `List` is equivalent to
`Int` (e.g., `length(L,L)`

).^{127This
is logically correct. An exception would be more appropriate, but to our
best knowledge, current practice in Prolog does not describe a suitable
candidate exception term.}