🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #3796

Re: Quintus Prolog Memory Management

#3796
From: Francois-Michel Lang
Date: Tue, 22 Nov 1988 14:03
48 lines
2647 bytes
Send, abort, edit, or list? l

In article <3@ubc-cs.UUCP>  kean@grads.cs.ubc.ca (Alex Kean) writes:
++ I was attempting to run a Quintus Prolog program that potentially generates
++ exponential number of clauses on the inputs.
...
++ I decided to test the memory by writing the following simple program: 
++  (1) an outer "loop" that run for "N" times; 
++  (2) an inner loop that mutiply a list of 10 chars ['1234567890']
++      for 18 times and never returns the list.
++ By calling "loop(300)" on the Sun4, the program crash and exits Quintus Prolog.
++ 
++ Questions: (a) Which stack has overflowed ?
++            (b) In general, what are the factors to observe when writing
++                prolog programs that takes up lots of memory. 
++ 
++ -------------------------------------------------------------------------
++ pair(0,_).
++ pair(N,X) :-
++   append(X,X,Z1),
++   N1 is N - 1,
++   pair(N1,Z1).
++ 
++ loop(0).
++ loop(N) :-
++   pair(18,['0123456789']),
++   !, garbage_collect,
++   J is N -1,
++   loop(J).
++ -------------------------------------------------------------------------

Well, one thing that will help right of the top is to add a couple of cuts
in the base cases of pair/2 and loop/1.  Without those cuts, you carry around
lots of superfluous choice points, and, what's worse, if you ever backtrack
into pair/2 or loop/1, you're going to be in trouble.
Also, if you add those cuts, the cut currently in the definition of loop/1
becomes unnecessary (I'm not too sure what it was doing in there in the first place).

I'll let Richard answer (a) and (b).
I also don't understand is the use of '0123456789',
and the claim that the program multiplies a list of 10 chars.
It looks to me that calling pair(N, L) will construct a list
consisting of 2^N copies of L appended together.
----------------------------------------------------------------------------
Francois-Michel Lang
Paoli Research Center, Unisys Corporation lang@prc.unisys.com (215) 648-7256
Dept of Comp & Info Science, U of PA      lang@cis.upenn.edu  (215) 898-9511
Technical Details
Message-ID: <8394@burdvax.PRC.Unisys.COM>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!husc6!mailrus!cornell!rochester!udel!burdvax!macbeth!lang
References: <ALF.88Oct2184429@hathor.sics.se > <818@etive.ed.ac.uk> <687@quintus.UUCP> <7919@megaron.arizona.edu> <3@ubc-cs.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!husc6!mailrus!cornell!rochester!udel!burdvax!macbeth!lang
From: lang@macbeth.PRC.Unisys.COM (Francois-Michel Lang)
Newsgroups: comp.lang.prolog
Subject: Re: Quintus Prolog Memory Management
Message-ID: <8394@burdvax.PRC.Unisys.COM>
Date: 22 Nov 88 14:03:21 GMT
References: <ALF.88Oct2184429@hathor.sics.se > <818@etive.ed.ac.uk> <687@quintus.UUCP> <7919@megaron.arizona.edu> <3@ubc-cs.UUCP>
Sender: news@PRC.Unisys.COM
Organization: Unisys Corporation, Paoli Research Center; Paoli, PA
Lines: 48