Add a clause as the last clause to the current active module. The argument of this predicate is, if it is a valid term, added after all the other predicates with the same functor and arity.
The clause to be added must have been declared dynamic. The dynamic/1 predicate can be used as a compile directive or as a normal built-in predicate. The clause to be added may also be non-existent if it is not declared as dynamic, i.e. no user-defined procedures exist.
see also: abolish/1 abolish/2 asserta/1 asserta/2 assertz/2 dynamic/1 dynamic/2 retract/1 retract/2 set_active_module/0 set_active_module/1
| Examples | |
| assertz(computer). | adds the fact 'computer' to current module after all other clauses of 'computer' with no arguments |
| assertz( test(I) :- do_something(I) ). | the complete predicate test(I) :- do_something(I) is added after all other test/1 predicates |
| Exceptions | |
| Clause is a variable | an instantiation_error exception is thrown because the argument is an empty variable |
| Head is variable | an instantiation_error exception is thrown because the head of the clause is a variable |
| Head is neither a variable nor a predication (=a well formed head of a clause term) | a type_error(callable, Head) exception is thrown |
| Body of the clause_term is not a well formed body_term | a type_error(callable, Body) exception is thrown |
| The predicate indicator Pred of the head of the clause_term is that of a static procedure | a permission_error(modify, static_procedure, Pred) exception is thrown |
| asserta(test). %there is no active module | the exception existence_error(active_module) is thrown, this exception is not defined in the ISO Prolog standard |