next up previous

12.9.4 Duplicating Template Facts

The duplicate action allows the user to duplicate deftemplate facts on the factlist changing a group of specified fields. This command allows a new fact to be created by copying most of the fields of a source fact and then specifying the fields to be changed. Only one fact may be duplicated with a single duplicate statement. The duplicate command is similar to the modify command except the fact being duplicated is not retracted.

Syntax

(duplicate <fact-specifier> <RHS-slot>*)

The term <fact-specifier> includes variables bound on the LHS to fact-addresses as described in section 5.4.1.8 or the fact-index of the desired fact (e.g. 3 for the fact labeled f-3). Note that the factindex generally is not known during the execution of a program, so facts usually are duplicated by binding them on the LHS of a rule. Static deftemplate checking is not performed when a factindex is used as the <fact-specifier> since the deftemplate being referenced is usually ambiguous. Only variables or fact indices may be used in a duplicate. External functions may not be called. The value returned by this function is the fact-address of the newly duplicated fact. If the assertion of the newly duplicated fact causes an error, or if an identical copy of the newly duplicated fact already exists in the factlist, then the symbol FALSE is returned.

Example

(defrule duplicate-part
   ?f1 <- (duplicate-part ?name)
   ?f2 <- (part (name ?name))
   =>
   (retract ?f1)
   (duplicate ?f2 (id (gensym*))))


next up previous