Article View: comp.lang.prolog
Article #1552Re: retract*all
From: Richard A. O'Keefe
Date: Tue, 06 Oct 1992 04:49
Date: Tue, 06 Oct 1992 04:49
54 lines
2577 bytes
2577 bytes
In article <uLBXRB2w165w@lcraft.ersys.edmonton.ab.ca>, cduguay@lcraft.ersys.edmonton.ab.ca (Claude Duguay) writes:
> This may seem sill or I might be missing part of this conversation but
> would it not be easier and just as portable to use a simpler
> implementation of retractall/retract_all rather than creating elaborate
> solutions to emulate compiler directives:
> myretractall(Term) :-
> retract(Term),
> fail.
> myretractall(_).
There are two snags:
(1) There may be substantial performance advantages to using the built in
method. (For example, Quintus Prolog uses the Lindholm/O'Keefe model
for data base changes, and retractall/1 could count as one "clock tick"
rather than several.)
(2) In a Prolog with modules, such as Quintus Prolog or ALS Prolog, you will
have to add some kind of declaration to myretractall/1, while the built
in version is already module-aware.
(3) The really big problem is that the indicated code for myretractall/1 is
wrong. For example, if I have
p(a).
p(b) :- q(c).
then retractall(p(_)) is supposed to retract _both_ clauses, but this
definition will only retract the first. You would need
myretractall(Term) :-
clause(Term, _, Ref),
erase(Ref),
fail ; true.
Because some Prolog vendors have not provided clause/3 and erase/1, you
would have to do something like
myretractall(Term) :-
clause(Term, Body),
my_retractall_aux(Term, Body),
fail ; true.
my_retractall_body(Head, Body) :- Body == true, !,
retract(Head),
!.
my_retractall_body(Head, Body) :-
retract(Head :- Body),
!.
It would all really be much simpler if vendors would just provide retractall/1
with the same name and semantics.
--
RMIT policy requires the use of Gender Inclusive Language in all publications
and in all information conveyed to students, staff, and potential job
applicants. Lapses into English are the sole responsibility of the author.
The Constitution of Australia does _not_ guarantee Freedom of Speech.
Technical Details
Message-ID:
<14905@goanna.cs.rmit.oz.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!know!cass.ma02.bull.com!mips2!news.bbn.com!olivea!spool.mu.edu!yale.edu!think.com!rpi!batcomputer!munnari.oz.au!bruce.cs.monash.edu.au!goanna!okReferences:
<uLBXRB2w165w@lcraft.ersys.edmonton.ab.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!know!cass.ma02.bull.com!mips2!news.bbn.com!olivea!spool.mu.edu!yale.edu!think.com!rpi!batcomputer!munnari.oz.au!bruce.cs.monash.edu.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.prolog Subject: Re: retract*all Message-ID: <14905@goanna.cs.rmit.oz.au> Date: 6 Oct 92 04:49:17 GMT References: <uLBXRB2w165w@lcraft.ersys.edmonton.ab.ca> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 54