assertz(+module_name, @clause_term)

Add a clause, as the last clause, to a loaded module. The first argument must be the name of a module currently loaded, not the filename of the file in the module. The second 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 or dynamic/2 predicates can be used as compile directives or as normal built-in predicates.

see also: abolish/1 abolish/2 asserta/1 assertz/1 asserta/2 dynamic/1 dynamic/2 retract/1 retract/2 set_active_module/0 set_active_module/1

Examples
assertz( data, computer ). adds the fact 'computer' to the module 'data' after all other clauses of 'computer' with no arguments
assertz( data, test(I) :- do_something(I) ). the complete predicate test(I) :- do_something(I) is added to the module 'data' after all other test/1 predicates
dynamic(data, hoi/1), assertz(data, hoi(arg)). declare hoi/1 as dynamic in the module 'data' and assert the term 'hoi' to that same module

 

Exceptions
The first argument is a variable an instantiation_error exception is thrown
The first argument Arg is not an atom a type_error(atom, Arg) exception is thrown
No module with the specified Name exists an existence_error(module, Name) exception is thrown.
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

 

 

info@trinc-prolog.com