🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #3093

back_retract

#3093
From: Bart Demoen
Date: Mon, 14 Mar 1988 19:18
37 lines
1435 bytes
See what you can do in BIMprolog:

back_retract((_h :- _b)) :-
		clause(_h,_b,_n) ,
		functor(_h,_f,_a) , functor(_nh,_f,_a) ,
		clause(_nh,_nb,_n) ,
		(retract((_h :- _b),_n) ;
		 assert((_nh :- _nb),_n) , fail ) .

clause/3 has as 3th argument the number of the clause:

	ex.  database =   a(x) .
			  a(y) .
			  a(z) .

		then  ?- clause(a(y),true,2) . succeeds
		and   ?- clause(a(X),true,3) . says:
			X = z
		and   ?- clause(a(x),true,N) . says:
			N = 1

the second argument in retract/2 has a similar meaning ;
in a call to assert/2, the 2nd arg must be instantiated and the clause is
asserted at the arg2'th place in the database; in this way, asserta/1 is just
a special case of assert/2, with definition:

	asserta(_x) :- assert(_x,1) .

so the query ?- assert(a(foo),3) . on the above database has as effect that the
database will look afterwards like:

                          a(x) .
                          a(y) .
                          a(foo) .
                          a(z) .

But there should be a better way of doing what you want.
Technical Details
Message-ID: <1194@kulcs.kulcs.uucp>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!mcvax!prlb2!kulcs!bimbart

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!mcvax!prlb2!kulcs!bimbart
From: bimbart@kulcs.uucp (Bart Demoen)
Newsgroups: comp.lang.prolog
Subject: back_retract
Message-ID: <1194@kulcs.kulcs.uucp>
Date: 14 Mar 88 19:18:40 GMT
Reply-To: bimbart@kulcs.UUCP (Bart Demoen)
Organization: Katholieke Universiteit Leuven, Dept. Computer Science
Lines: 37