asserta(+atom_module, @clause_term)

Add a new clause, as the first, to a module in the clausebase. 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, inserted in front of 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 assertz/2 dynamic/1 dynamic/2 Prolog modules retract/1 retract/2 set_active_module/0 set_active_module/1

Examples
asserta( data, computer ). adds the fact 'computer' to the module identified by the name 'data' in front of all other clauses of 'computer' with no arguments
asserta( data, test(I) :- do_something(I) ). the complete predicate test(I) :- do_something(I) is added to the module 'data' in front of all other predicates test with 1 argument
dynamic(data, hoi/0), asserta(data, hoi). declare hoi/0 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 thrwon
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
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