lengthlist(+List, ?Num)

Determine the number of elements in the List (first parameter) and unify that number with the second parameter Num.

This predicate is located in the file 'list.txt', use ensure_loaded/1 to include this file.

see also: conc/3 del/3 largest_number/2 last/2 member/2 prefix/2 reverse/2 smallest_number/2 sublist/2 suffix/2 sum_list/2 sum_list_integer/2

Example
lengthlist([], L). succeeds and parameter L is unified with 0,
L=0
lengthlist([a, b, c], L). succeeds and variable L is unified the number of elements in the list [a,b,c]
L=3
lengthlist([a, b, c], 4). fails because the list [a,b,c] contains 3 elements and this value cannot be unified with the value 4

 

 

info@trinc-prolog.com