]> Repositorios git - scryer-prolog.git/commitdiff
assertz/1, asserta/1, retract/1, retractall/1 are meta-predicates (#902, #903)
authorMark Thom <[email protected]>
Wed, 14 Apr 2021 21:10:45 +0000 (15:10 -0600)
committerMark Thom <[email protected]>
Wed, 14 Apr 2021 21:28:16 +0000 (15:28 -0600)
src/indexing.rs
src/lib/builtins.pl
src/loader.pl

index 0f368356e56c60f5b75f2172385593ffe3e48750..a71ab01f9d866058b4a32b3cfc7a15ebae41a685 100644 (file)
@@ -37,7 +37,7 @@ impl OptArgIndexKey {
         match (self, key_type) {
             (OptArgIndexKey::Constant(..), OptArgIndexKeyType::Constant)
             | (OptArgIndexKey::Structure(..), OptArgIndexKeyType::Structure)
-            // | (OptArgIndexKey::List(..), OptArgIndexKeyType::List) 
+            // | (OptArgIndexKey::List(..), OptArgIndexKeyType::List)
             => true,
             _ => false,
         }
@@ -116,7 +116,12 @@ impl<'a> IndexingCodeMergingPtr<'a> {
                 constants.insert(constant.clone(), constant_ptr);
             }
             _ => {
-                unreachable!()
+                if let IndexingCodePtr::DynamicExternal(_) = constant_ptr {
+                    // this must be a defunct clause, because it's been deleted
+                    // from the skeleton.
+                } else {
+                    unreachable!()
+                }
             }
         }
 
@@ -378,7 +383,12 @@ impl<'a> IndexingCodeMergingPtr<'a> {
                 structures.insert((name.clone(), *arity), structure_ptr);
             }
             _ => {
-                unreachable!()
+                if let IndexingCodePtr::DynamicExternal(_) = structure_ptr {
+                    // this must be a defunct clause, because it's been deleted
+                    // from the skeleton.
+                } else {
+                    unreachable!()
+                }
             }
         }
 
index 1b25467430aec126a97fe5e5f58e81b8d6dab0fc..c7ea80014280e7f64fba3bb607de308a34cca6a0 100644 (file)
@@ -818,6 +818,8 @@ module_asserta_clause(Head, Body, Module) :-
     ;  callable(Head), functor(Head, Name, Arity) ->
        (  '$head_is_dynamic'(Module, Head) ->
           call_asserta(Head, Body, Name, Arity, Module)
+       ;  '$no_such_predicate'(Module, Head) ->
+          call_asserta(Head, Body, Name, Arity, Module)
        ;  throw(error(permission_error(modify, static_procedure, Name/Arity), asserta/1))
        )
     ;  throw(error(type_error(callable, Head), asserta/1))
@@ -840,6 +842,8 @@ asserta_clause(Head, Body) :-
     ;  throw(error(type_error(callable, Head), asserta/1))
     ).
 
+:- meta_predicate asserta(0).
+
 asserta(Clause) :-
     (  Clause \= (_ :- _) ->
        Head = Clause,
@@ -888,6 +892,8 @@ assertz_clause(Head, Body) :-
     ;  throw(error(type_error(callable, Head), assertz/1))
     ).
 
+:- meta_predicate assertz(0).
+
 assertz(Clause) :-
     (  Clause \= (_ :- _) ->
        Head = Clause,
@@ -973,6 +979,8 @@ retract_clause(Head, Body) :-
     ;  throw(error(type_error(callable, Head), retract/1))
     ).
 
+:- meta_predicate retract(0).
+
 retract(Clause) :-
     (  Clause \= (_ :- _) ->
        Head = Clause,
@@ -983,6 +991,14 @@ retract(Clause) :-
     ).
 
 
+:- meta_predicate retractall(0).
+
+retractall(Head) :-
+   retract((Head :- _)),
+   false.
+retractall(_).
+
+
 module_abolish(Pred, Module) :-
     (  var(Pred) ->
        throw(error(instantiation_error), abolish/1)
@@ -996,7 +1012,7 @@ module_abolish(Pred, Module) :-
              throw(error(domain_error(not_less_than_zero, Arity), abolish/1))
              ;  max_arity(N), Arity > N ->
              throw(error(representation_error(max_arity), abolish/1))
-             ;  callable(Head), functor(Head, Name, Arity) ->
+             ;  functor(Head, Name, Arity) ->
                 (  '$head_is_dynamic'(Module, Head) ->
                    '$abolish_clause'(Module, Name, Arity)
                 ;  throw(error(permission_error(modify, static_procedure, Pred), abolish/1))
@@ -1007,6 +1023,9 @@ module_abolish(Pred, Module) :-
     ;  throw(error(type_error(predicate_indicator, Module:Pred), abolish/1))
     ).
 
+
+:- meta_predicate abolish(0).
+
 abolish(Pred) :-
     (  var(Pred) ->
        throw(error(instantiation_error), abolish/1)
@@ -1024,7 +1043,7 @@ abolish(Pred) :-
              throw(error(domain_error(not_less_than_zero, Arity), abolish/1))
              ;  max_arity(N), Arity > N ->
              throw(error(representation_error(max_arity), abolish/1))
-             ;  callable(Head), functor(Head, Name, Arity) ->
+             ;  functor(Head, Name, Arity) ->
                 (  '$head_is_dynamic'(user, Head) ->
                 '$abolish_clause'(user, Name, Arity)
                 ;  '$no_such_predicate'(user, Head) ->
@@ -1585,8 +1604,3 @@ callable(X) :-
        true
     ;  false
     ).
-
-retractall(Head) :-
-   retract((Head :- _)),
-   false.
-retractall(_).
index 89eac918ec535a7aa7a39132a69f6c606f6f42a8..eb79c1627defc29fa7e6724621aa574aa33c8211 100644 (file)
@@ -365,7 +365,6 @@ compile_declaration(discontiguous(Name/Arity), Evacuable) :-
     '$add_discontiguous_predicate'(Module, Name, Arity, Evacuable).
 compile_declaration(initialization(Goal), Evacuable) :-
     prolog_load_context(module, Module),
-    '$add_dynamic_predicate'(Module, '$initialization_goals', 1, Evacuable),
     assertz(Module:'$initialization_goals'(Goal)).
 compile_declaration(set_prolog_flag(Flag, Value), _) :-
     set_prolog_flag(Flag, Value).