fork download
  1. getlength(L,N) :-
  2. retractall(getlength_res(_)),
  3. assert(getlength_res(0)),
  4. retractall(getlength_list(_)),
  5. assert(getlength_list(L)),
  6. (
  7. getlength_list([]), !, getlength_res(N)
  8. ;
  9. retract(getlength_res(V)), W is V + 1, assert(getlength_res(W)),
  10. retract(getlength_list([_|T])), assert(getlength_list(T)), fail
  11. ).
  12.  
  13. main:-
  14. getlength([1,2,3,4,5,6], X),
  15. writeln(X),
  16. getlength([], Y),
  17. writeln(Y)
  18. .
  19.  
  20. :- main.
Success #stdin #stdout #stderr 0.02s 6160KB
stdin
Standard input is empty
stdout
6
0
stderr