summaryrefslogtreecommitdiff
path: root/stdlib.pl
diff options
context:
space:
mode:
authorPeter Mikkelsen <peter@pmikkelsen.com>2021-07-09 20:09:22 +0000
committerPeter Mikkelsen <peter@pmikkelsen.com>2021-07-09 20:09:22 +0000
commita37ae2f0170499be1a95031d24ff86aac5cf46f1 (patch)
treefcd3a769a460a5b8a5b54c53cd70ed5d2834a73a /stdlib.pl
parentd2a0828140c31514c514b8e4fb9a4d52c389d8fe (diff)
Add asserta/1, assertz/1, retract/1, abolish/1 (and retract_one/1, which is retract/1 but doesn't backtrack)
Diffstat (limited to 'stdlib.pl')
-rw-r--r--stdlib.pl12
1 files changed, 9 insertions, 3 deletions
diff --git a/stdlib.pl b/stdlib.pl
index a972ae0..528781b 100644
--- a/stdlib.pl
+++ b/stdlib.pl
@@ -10,8 +10,7 @@ once(Goal) :-
repeat :- true ; repeat.
-% Control structures.
-true.
+% Control structures.
If -> Then :-
If, !, Then.
@@ -150,7 +149,7 @@ E1 > E2 :-
E2 < E1.
-% Clause retrieval and information
+% Clause retrieval and information and removal
clause(Head, Body) :-
clause(Head, Body, Clauses),
@@ -160,6 +159,13 @@ current_predicate(PI) :-
current_predicate(PI, Predicates),
member(PI, Predicates).
+retract(Clause) :-
+ copy_term(Clause, ClauseCopy),
+ retract_one(ClauseCopy),
+ ( Clause = ClauseCopy
+ ; retract(Clause)
+ ).
+
% Basic list predicates
member(X, [X|_]).
member(X, [_|Tail]) :-