asserta(@clause_term) [ISO]

Add a new clause, as the first, to the current active module. The 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. 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 assertz/1 asserta/2 assertz/2 dynamic/1 dynamic/2 retract/1 retract/2 set_active_module/0 set_active_module/1

Examples
asserta(computer). adds the fact 'computer' to current module in front of all other clauses of 'computer' with no arguments
asserta( test(I) :- do_something(I) ). the complete predicate test(I) :- do_something(I) is added in front of all other predicates test with 1 argument

 

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

 

 

info@trinc-prolog.com