/*  Exploring Languages with Interpreters and Functional Programming
    Copyright (C) 2018, H. Conrad Cunningham

1234567890123456789012345678901234567890123456789012345678901234567890

    2018-05-29: Recreated from book Chapter 2

    swipl Counting.pl
    main.

*/

counter(X,Y,S) :- count(X,Y,R), atomics_to_string(R,'\n',S).

count(X,X,[X]). 
count(X,Y,[])     :- X  > Y. 
count(X,Y,[X|Rs]) :- X < Y, NX is X+1, count(NX,Y,Rs).

main :- counter(0,10,S), write(S).
