home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * *
- * The SB-Prolog System *
- * Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987 *
- * *
- ************************************************************************/
-
- /*-----------------------------------------------------------------
- SB-Prolog is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY. No author or distributor
- accepts responsibility to anyone for the consequences of using it
- or for whether it serves any particular purpose or works at all,
- unless he says so in writing. Refer to the SB-Prolog General Public
- License for full details.
-
- Everyone is granted permission to copy, modify and redistribute
- SB-Prolog, but only under the conditions described in the
- SB-Prolog General Public License. A copy of this license is
- supposed to have been given to you along with SB-Prolog so you
- can know your rights and responsibilities. It should be in a
- file named COPYING. Among other things, the copyright notice
- and this notice must be preserved on all copies.
- ------------------------------------------------------------------ */
-
- /****************************************************************************
- * *
- * This file has been changed by to include Modules Extensions *
- * Changes by : Brian Paxton 1991/92 *
- * Last update : June 1992 *
- * *
- * Organisation : University of Edinburgh. *
- * For : Departments of Computer Science and Artificial Intelligence *
- * Fourth Year Project. *
- * *
- ****************************************************************************/
-
- /* $retr.P */
-
- /* retract routines */
-
- $retr_export([$retract/1,$retr_abolish/1,$retr_abolish/2,$update/2,
- $retractall/1,$retract/2,$retractall/2]).
-
- % $retr_use : $bmeta, $buff, $db, $assert, $modules, $decompile
-
- /* this routine $retracts facts. It does so by running the chain of buffers,
- explicitly. When it finds a fact that unifies, it overwrites the first
- instruction in the buffer (after the retrymeelse instruction) to be a
- fail. This is somewhat of a kludge but is easy. Besides you shouldn't be
- using $retract anyway. */
-
- $retract(Clause) :-
- $retract(Clause,perv).
-
- % Clauses are now preprocessed to check that they are not functions and are
- % then moved to the required structure before the retract is issued.
- % (Similar to code for assert).
-
- $retract(Clause,Tag) :-
- ( $isa_structuretag(Tag) ->
- ( $retr_chk_clause(Clause) ->
- ( ( Tag = perv -> Clause2 = Clause ;
- ( $check_destination(Clause,Oldtag),
- $move_clause(Clause,Oldtag,Tag,Clause1),
- $fun_rel(Clause1,Clause2,Tag) ) ),
- $check_not_function(Clause2),
- ((Clause2 = (Head :- Body) ->
- true ;
- (Clause2 = Head, Body = true)
- ),!,
- $clause(Head,Body,Ref),
- $erase(Ref)
- ) ;
- ($telling(X), $tell(stderr),
- $write('*** Error: illegal argument to retract: '),
- $write(Clause), $nl,
- $told, $tell(X)
- ) ) ) ;
- ( $telling(X), $tell(stderr),
- $writename('*** Error: Second arg to retract/2 must be a structure tag'),
- $nl, $told, $tell(X) ) ).
-
- $retr_chk_clause(Cl) :- $atom(Cl).
- $retr_chk_clause(Cl) :-
- $structure(Cl),
- (Cl = (Hd :- Body) -> $retr_chk_hd(Hd) ; true).
-
- $retr_chk_hd(Hd) :- $atom(Hd).
- $retr_chk_hd(Hd) :- $structure(Hd), Hd \= (_ :- _).
-
- $retr_abolish(Goal) :- $buff_code(Goal,0,11,0).
- $retr_abolish(Pred,Arity) :-
- ($atom(Pred), integer(Arity)) ->
- ($functor(Term,Pred,Arity), $retr_abolish(Term)) ;
- ($writename('*** abolish: illegal argument: '),
- $write(Pred), $writename('/'), $write(Arity), $nl,
- fail
- ).
-
- /* the following routines allow a tuple to be updated in a very limited way.
- Using these operations, you can change the value of an existing tuple in the
- database. The tuple must have been asserted, and only the first field
- can be changed and only if it is a constant or an integer. */
-
- /* $upda_clref(Newval,Clref): Newval must be bound to a constant or integer,
- and Clref must be bound to a clause reference. The first field of the tuple
- in Clref must be a constant or integer. This operation resets that first
- field to Newval. */
-
- $upda_clref(Newval,Clref) :-
- integer(Newval),!,
- $buff_code(Clref,10,6 /*gb*/ ,14 /*getnumcon*/), /* right already */
- $buff_code(Clref,12,2 /*pn*/ ,Newval).
-
- $upda_clref(Newval,Clref) :-
- $atom(Newval),!,
- $buff_code(Clref,10,6 /*gb*/ ,4 /*getcon*/), /*must already be right*/
- $buff_code(Clref,12,1 /*pppsc*/ ,Newval).
-
- $update(Fact,Newval) :-
- $assert_get_prref(Fact,Prref),$db_call_prref_s(Fact,Prref,Clref),
- $upda_clref(Newval,Clref).
-
- $retractall(Hd) :-
- $retractall(Hd,perv).
-
- % Again, extensions here are so references to remote structures can be used.
- % See above.
-
- $retractall(Hd,Tag) :-
- ( $isa_structuretag(Tag)
- -> ( $retr_chk_hd(Hd) ->
- ( ( Tag == perv -> Hd1 = Hd ;
- ( $check_destination(Hd,Oldtag),
- $move_clause(Hd,Oldtag,Tag,Hd1) ) ),
- $check_not_function(Hd1),
- $retractall1(Hd1) ) ;
- ($telling(X), $tell(stderr),
- $write('*** Error: illegal argument to retractall/1: '),
- $write(Hd), $nl,
- $told, $tell(X)));
- ( $telling(X), $tell(stderr),
- $writename('*** Error: Second arg to retractall/2 must be a structure tag'),
- $nl, $told, $tell(X) ) ).
-
- $retractall1(Hd) :-
- $clause(Hd,_,Ref),
- $erase(Ref),
- fail.
- $retractall1(_).
-
-
- /* ------------------------------ $retr.P ------------------------------ */
-
-