練習。
% span.pro :- module(span, [span/2]). span(From, From, [From]) :- !. span(From, To, [From|Span]) :- From < To, From1 is From + 1, span(From1, To, Span), !.
% span-test.pro :- include(span). main :- span(1, 10, S), format("~p~n", [S]), halt.
実行。
$ gprolog --consult-file span-test.pro --entry-goal main [1,2,3,4,5,6,7,8,9,10]
通常使うには between
で充分なのだけれど。
$ gprolog | ?- findall(N, between(1, 10, N), NS). NS = [1,2,3,4,5,6,7,8,9,10] yes