Prolog length of a list

前端 未结 2 1837
星月不相逢
星月不相逢 2021-01-21 07:51

How can I calculate the length of a list

?- size_sub([[b,a,g], [9,3,7,4], [6]],  X).
X = [3, 4, 1].

?- size_sub([[c,g,e,w], [7]],  X).
X = [4, 1].

?- size_sub(         


        
2条回答
  •  逝去的感伤
    2021-01-21 08:31

    To map length/2 over a list of lists, we can use the meta-predicate maplist/3 like this:

    size_sub(Xss,Ls):-
        maplist(length,Xss,Ls).
    

提交回复
热议问题