How can I count nested list elements in Prolog? I have the following predicates defined, which will count a nested list as one element:
length([ ], 0).
length([H|T],N) :- length(T,M), N is M+1.
Usage:
?- length([a,b,c],Out).
Out = 3
This works, but I would like to count nested elements as well i.e.
length([a,b,[c,d,e],f],Output).
?- length([a,b,[c,d,e],f],Output).
Output = 6