Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!cam-news-feed3.bbnplanet.com!cam-news-hub1.bbnplanet.com!news.bbnplanet.com!howland.erols.net!news.nacamar.de!uunet!in2.uu.net!uucp2.uu.net!sangam!konark!saathi.ncst.ernet.in!sasi
From: Sasikumar M <sasi@saathi.ncst.ernet.in>
Subject: Re: interval to a list
In-Reply-To: <5dbi7k$4ek@mulga.cs.mu.OZ.AU>
X-Nntp-Posting-Host: saathi.ncst.ernet.in
Content-Type: TEXT/PLAIN; charset=US-ASCII
Message-ID: <Pine.ULT.3.94.970212132225.4677B-100000@saathi.ncst.ernet.in>
Sender: news@konark.ncst.ernet.in (News Administration)
Organization: National Centre for Software Technology, Bombay, India
References: <32F496D3.1EA7@cips2.gm.fh-koeln.de> <E53Isu.65C.0.staffin.dcs.ed.ac.uk@dcs.ed.ac.uk> <32F7D080.1FC7@dial.pipex.com> <5da030$6d1@mulga.cs.mu.OZ.AU> <32F8B5C4.7321@dial.pipex.com> <5dbi7k$4ek@mulga.cs.mu.OZ.AU>
Mime-Version: 1.0
Date: Wed, 12 Feb 1997 08:00:19 GMT
Lines: 42



On 6 Feb 1997, Fergus Henderson wrote:

[... snip ...]
> ] >  >interval( A, B, [A|Rest] ):-
> ] >  >       A < B,
> ] >  >       NewA is A+1,
> ] >  >        interval( NewA, B, Rest ) .
> ] >  >interval( X, X, [X] ).
> ] > 
> 
> ] > Note that unless you are assuming that your Prolog compiler is quite
> ] > smart, your code has a performance bug, because it leaves lots of
> ] > choice points around. This will have the further effect of preventing
> ] > the system from reclaiming garbage, so your code can cause space leaks.

Is this really serious? Quite likely, the routine is called with a
fairly small interval size, say about 5 or less. Is the space loss that
significant, in such cases?

Second, can't the bug be cleared by just inserting a cut after A < B?
That will tell (good) Prologs that a choice point is required. Or the
same can be easily transformed to a simple if-then-else.

Third, if the routine is called from some other procedure, choice
points could be cut from there also.. While the use of space is possibly
important in the general case, the program given here does not seem
too far from the efficient version that Ferguson has in mind.

Or am I missing something?

> ] > This is a good example of why Prolog is IMHO an awful language to use
> ] > if you're the least bit interested in performance.

This again, is presumably true of all languages. Are there any really
good exceptions?

  - Sasikumar



