In Prolog, a procedure is either static or dynamic. A static procedure is one whose facts/rules are predefined at the start of execution, and do not change during execution. Normally, the facts/rules will be in a file of Prolog code which will be loaded during the Prolog session. Sometimes, you might want to add extra facts (or maybe even extra rules) to the procedure, during execution of a Prolog query, using assert/asserta/assertz", or maybe remove facts/rules using retract/retractall. To do this, you must declare the procedure to be dynamic.

You can declare a procedure to be dynamic by including in your code (normally adjacent to the facts/rules for that procedure) a suitable dynamic directive. Example - suppose you have a procedure called likes, with arity 2, and you have a "starter set" of facts/rules in your Prolog program, but you want to infer extra facts about likes during execution, and add them to the data base so that they don't need to be recomputed each time they are used. [You would normally only do this - add the new facts to the database - if the extra facts were slow to compute.] You need to declare likes (with arity 2) to be dynamic. You do this as follows:

:- dynamic likes/2.

[By the way, notice that this leaves open the possibility that a different version of likes (with arity 3, say) might not be dynamic.]

See also memoisation.