Re: change_arg/3 = nb_linkarg/3 ? (Was: PIPs from the Basilisk Chamber)

Liste des GroupesRevenir à cl prolog 
Sujet : Re: change_arg/3 = nb_linkarg/3 ? (Was: PIPs from the Basilisk Chamber)
De : janburse (at) *nospam* fastmail.fm (Mild Shock)
Groupes : comp.lang.prolog
Date : 08. Nov 2024, 18:39:26
Autres entêtes
Message-ID : <vglicd$lhqn$2@solani.org>
References : 1 2 3 4 5 6 7 8 9 10 11 12
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.19
Interestingly the findall2/3 is not
impressed by calling garbage_collect/0
or trim_stacks/0:
/* SWI-Prolog 9.3.14 */
?- findall2(Y-X-Y, (between(1,10,X);garbage_collect,
     trim_stacks, between(11,20,X)), L), write(L).
[_212-1-_212,_230-2-_230,_248-3-_248,_266-4-_266,
_284-5-_284,_302-6-_302,_320-7-_320,_338-8-_338,
_356-9-_356,_374-10-_374,_396-11-_396,_418-12-_418,
_440-13-_440,_462-14-_462,_484-15-_484,_506-16-_506,
_528-17-_528,_550-18-_550,_572-19-_572,_594-20-_594]
Memory consumption is also the same:
?- between(4,8,K), N is 10^K, space(findall(X,
between(1,N,X),_)), fail; true.
% Memory 0.229 mB
% Memory 4.162 mB
% Memory 33.522 mB
% Memory 268.403 mB
ERROR: Stack limit (1.0Gb) exceeded
?- between(4,8,K), N is 10^K, space(findall2(X,
between(1,N,X),_)), fail; true.
% Memory 0.393 mB
% Memory 4.063 mB
% Memory 33.423 mB
% Memory 268.304 mB
ERROR: Stack limit (1.0Gb) exceeded
But I still do not 100% believe that
it works...
Mild Shock schrieb:
I came up with a findall/3 for SWI-Prolog that
doesn’t use call_cleanup/2. The findall2/3 realization
uses nb_linkarg/3 and duplicate_term/2.
 findall2(Template, Goal, List) :-
    sys_find2_init(State),
    (Goal, sys_find2_next(Template, State), fail; true),
    sys_find2_fini(State, List).
 sys_find2_init(X) :-
    X = v(_,_),
    C = [-|_],
    nb_linkarg(1, X, C),
    nb_linkarg(2, X, C).
 sys_find2_next(T, X) :-
    C = [_|_],
    duplicate_term(T, H),
    nb_linkarg(1, C, H),
    arg(1, X, J),              %%% known end cell
    nb_linkarg(2, J, C),
    nb_linkarg(1, X, C).
 sys_find2_fini(v(C,D), L) :-
    nb_linkarg(2, C, []),
    arg(2, D, L).
 Its not as fast as the bundled findall/3.

Date Sujet#  Auteur
29 Sep 24 * PIPs from the Basilisk Chamber (Was: 50 Years of Prolog Nonsense)7Mild Shock
8 Nov 24 +* Prolog Pearls I: Barklund and Millroth (Was: PIPs from the Basilisk Chamber)4Mild Shock
8 Nov 24 i`* Prolog Pearls II: Barklund and Millroth (Was: PIPs from the Basilisk Chamber)3Mild Shock
8 Nov 24 i `* change_arg/3 = nb_linkarg/3 ? (Was: PIPs from the Basilisk Chamber)2Mild Shock
8 Nov 24 i  `- Re: change_arg/3 = nb_linkarg/3 ? (Was: PIPs from the Basilisk Chamber)1Mild Shock
9 Nov 24 `* Re: PIPs from the Basilisk Chamber (Was: 50 Years of Prolog Nonsense)2Mild Shock
9 Nov 24  `- Re: PIPs from the Basilisk Chamber (Was: 50 Years of Prolog Nonsense)1Mild Shock

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal