To count the number of elements in a list in PROLOG. Earthcare Foundation NGO 22:14 Prolog No comments list([],0). list([H|T],C):-list(T,Y),C is Y+1. Output 1 ?- list([1,2,3,5],C). C = 4. 2 ?- list([1,2,3,5,4,5,6,7],C). C = 8. 3 ?- list([],C). C = 0. Share This: Facebook Twitter Google+ Stumble Digg Email ThisBlogThis!Share to XShare to Facebook
0 comments:
Post a Comment