BOUNCE mercury-users at Non-member submission from [Don Smith <dsmith at>]

Thomas Charles CONWAY conway at
Tue Oct 21 08:12:36 AEST 1997

In mercury-users at, Don writes:
> I am writing a Prolog application which builds a graph structure level
> by level.  To extend the (ground) graph to a new level the program calls
> setof/3 to collect solutions, each of which references the graph from
> earlier levels.  When I run the program under sicstus 2.1, eclipse 3.5.2,
> or BinProlog 5.0, it uses way too much memory.   The problem seems to be
> that setof/3 copies terms in each solution, so each time a new solution
> is collected the entire existing graph is copied, even though the graph
> is ground and could in fact be shared.
> I need a Prolog which will be smart enough to (let me specify that it's OK
> to) copy only the new part of each solution.   Do you think Mercury might
> do this, thanks to its use of mode info?   Will any standard Prologs let 
> me do this?

If you are using the Bohem conservative garbage collector (the default)
then the all-solutions predicates do no copying at all (and there is
no heap-reclaimation on failure). If you are using no collection,
then only the new parts of your solution get copied.

BTW, from your description what you are building is a DAG rather
than a general graph. Mercury can't directly represent a general
graph (which requires rational terms rather than regular terms).
We do, however, have library functionality for building graphs
as abstract data types.

Thomas Conway               				      conway at
AD DEUM ET VINUM	  			      Every sword has two edges.

More information about the users mailing list