Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.mathworks.com!zombie.ncsc.mil!paladin.american.edu!news.ecn.uoknor.edu!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: problems with bagof
Message-ID: <9520601.9824@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
References: <3tbv33$7ps@due.unit.no> <3tpqts$t1b@goanna.cs.rmit.edu.au> <ludemannDBIvv5.KCG@netcom.com> <3uclb9$d01@goanna.cs.rmit.edu.au>
Date: Mon, 24 Jul 1995 15:56:45 GMT
Lines: 44

ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe) writes:

>I actually did some benchmarking with a couple of implementations; I wanted
>to see if effectively compiling
>
>	setof(Template, Generator, Set)
>
>as
>	<preprocess>
>	(   mark,
>	    Generator,
>	    save Template,
>	    fail
>	;   recover Results,
>	    parse Results getting Set and bindings for free variables
>	)
>
>so that the Generator could be compiled in-line would improve things.
>The answer for all the tests I could get my hands on was NO.  If the
>interpreter is any good, the overhead of call/1 here will be swamped
>by the cost of saving the results and picking them up again (two copies
>are required, though if you are _really_ cunning you can get the cost
>down to the equivalent of one copy) and especially the cost of sorting
>them.

Incidentally, in the current Mercury implementation solutions/2
(which is our answer to setof/3, NU-Prolog's solutions/3, etc.)
has a "zero-copy" implementation.

In this case I expect that what you gain on the swings you
lose on the round-abouts.  With the current conservative garbage
collector, we don't get cheap memory reclamation on backtracking.
With a different garbage collector the trade-offs would change,
and we probably adopt a different implementation of solutions/2.

Still, it's nice to be able to say we've gone one better ;-)
In our implementation, solutions/2 is cheap, it is creating
garbage that is expensive.

-- 
Fergus Henderson              | Designing grand concepts is fun;
fjh@cs.mu.oz.au               | finding nitty little bugs is just work.
http://www.cs.mu.oz.au/~fjh   | -- Brooks, in "The Mythical Man-Month".
PGP key fingerprint: 00 D7 A2 27 65 09 B6 AC  8B 3E 0F 01 E7 5D C4 3F
