Scryer-prolog: Memory leak in spite of cut

Created on 21 Feb 2020  路  7Comments  路  Source: mthom/scryer-prolog

a :-
    !,
    a.
a.

Above program should run indefinitely in constant space but it does not.

Most helpful comment

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 (;).

All 7 comments

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 (;).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

triska picture triska  路  4Comments

triska picture triska  路  4Comments

XVilka picture XVilka  路  3Comments

UWN picture UWN  路  3Comments

triska picture triska  路  3Comments