`length/2`

`length(`

`?List``, `

`?Integer``)`

`Integer` is the length of `List`. If `List` is
instantiated to a proper list of term, or `Integer` to an integer,
the predicate is determinate.

`List`- list of term
`Integer`- integer, non-negative

If `List` is a list of indefinite length (that is, either a variable
or of the form `[...|X]`

, where `X`

is a variable) and if `Integer` is bound to an integer,
then `List` is made to be a list of length `Integer` with unique
variables used to “pad” the list. If `List` cannot be
made into a list of length `Integer`, the call fails.

| ?-List = [a,b|X], length(List, 4).List = [a,b,_A,_B], X = [_A,_B];| ?-

If `List` is bound, and is not a list, `length/2`

simply fails.

If `List` is a cyclic list, and `Integer` is bound to a
non-negative integer, then `length/2`

simply fails.

If `List` is a cyclic list, and `Integer` is a variable, the
behavior is unspecified and may change in the some future version.

If `Integer` is unbound, then it is unified with all possible lengths
for the list `List`.

`type_error`

`Integer`is not an integer`domain_error`

`Integer`< 0

| ?-length([1,2], 2).yes | ?-length([1,2], 0).no | ?-length([1,2], X).X = 2;no

ref-lte-acl,
`library(lists)`

.

Send feedback on this subject.