a :-
!,
a.
a.
Above program should run indefinitely in constant space but it does not.
Idem d :- once((true;true)), d.
This is needed to actually evaluate the partial strings implementation.
Here is an attempt to test partial strings, but it does run out of space
:- module(lengelize,[lengelize/0]).
% :- set_prolog_flag(double_quotes, codes).
datum("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz").
lengelize :-
datum(L),
len_(L, 0,N),
lenloop(L, N).
lenloop(L, N) :-
len_(L, 0, M),
N == M,
lenloop(L, N).
len_([], N,N).
len_([_|L], N0,N) :-
N1 is N0+1,
len_(L, N1,N).
And, I do not understand why the directive above is rejected. My plan was to compare the various lists with each other. It's written like that to circumvent the memory leaks of the cut.
?- lengelize:lenloop([],0). leaks too
This still leaks, but it is much slower in growth. Probably you do needless put-unsafe allocations.
Right. I know where the remaining growth is coming from. I should have it addressed in another day or two.
The lengelize program now runs in constant space, and so does the first program you posted.
The second does not run in constant space, and won't until I add a garbage collector. Incidentally, you could expand it manually to d :- (true;true), !, d. and it would then run in constant space, but only because the compiler inlines (;).
Most helpful comment
The
lengelizeprogram now runs in constant space, and so does the first program you posted.The second does not run in constant space, and won't until I add a garbage collector. Incidentally, you could expand it manually to
d :- (true;true), !, d.and it would then run in constant space, but only because the compiler inlines(;).