First create a string containing the rule (or any other construct) and then use the build function:
CLIPS>
(deftemplate action
(slot prev)
(slot curr)
)
CLIPS>
(defrule test
(action (prev ?p))
=>
(build (str-cat
"(defrule test_inner
(action (curr " ?p "))
=>
(printout t \"Result of a newly created rule.\")
)"
)
)
)
CLIPS> (reset)
CLIPS> (assert (action (prev move)))
<Fact-1>
CLIPS> (agenda)
0 test: f-1
For a total of 1 activation.
CLIPS> (run)
CLIPS> (rules)
test
test_inner
For a total of 2 defrules.
CLIPS> (ppdefrule test_inner)
(defrule MAIN::test_inner
(action (curr move))
=>
(printout t "Result of a newly created rule."))
CLIPS>