Search code examples
clips

Obtain ID of fact I just asserted


Is there a way for me to get the fact ID of a fact that I just asserted in the RHS of a rule? Something along the lines of

?f <- (assert (new-fact))

Solution

  • CLIPS> 
    (defrule example
       =>
       (bind ?f (assert (new-fact)))
       (bind ?i (fact-index ?f))
       (printout t "The fact index is " ?i crlf))
    CLIPS> (reset)
    CLIPS> (run)
    The fact index is 1
    CLIPS> (facts)
    f-0     (initial-fact)
    f-1     (new-fact)
    For a total of 2 facts.
    CLIPS>