🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #4082

retractall and backtracking

#4082
From: Nigel Cliffe
Date: Thu, 08 Jun 1989 08:07
39 lines
1740 bytes
I have a problem with backtracking, and retracts that don't appear to
happen - here is a simplified example:

If I have a database with repeated facts in it and want to a) get just the
unique entries, and b) retract the contents of the database as I get those
entries then one way that ought to work is this:

:- dynamic foo/1.
foo(bar1).
foo(bar1).
foo(bar2).

write_unique_foos :-
	foo(X),
	write(X),nl,
	retractall(foo(X)),
	fail.

Now if the predicate "write_unique_foos" is called, then I get all three
values for foo written, not just the two unique ones as I would expect.
However if I trace the execution, and test the contents of the database at
various points from the debugger then "foo(bar1)" has disappeared after the
first call to "retractall".

Can anyone explain why this happens.

   I know that I can get the result I want by using setof, and probably 
hundreds of other methods as well, I'm just curious as to why things don't
behave as I would expect.

Just incase this is system dependent, I'm using Quintus 2.4 on a Sun3 running
Sun OS 3.5.

-- 
   Nigel Cliffe  - 

     British Telecom Research Labs, Martlesham Heath, Ipswich, IP5 7RE, UK
   voice: +44 473 645275   fax: +44 473 637557   email: nigel@hfnet.bt.co.uk
Technical Details
Message-ID: <575@hfserver.hfnet.bt.co.uk>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!mcvax!ukc!axion!hfserver!nigel

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!mcvax!ukc!axion!hfserver!nigel
From: nigel@hfserver.hfnet.bt.co.uk (Nigel Cliffe)
Newsgroups: comp.lang.prolog
Subject: retractall and backtracking
Keywords: Quintus, retract, backtracking
Message-ID: <575@hfserver.hfnet.bt.co.uk>
Date: 8 Jun 89 08:07:02 GMT
Organization: British Telecom Research Labs, Martlesham Heath, Ipswich, Suffolk UK
Lines: 39