Search code examples
clipsfact

How to get information from the fact in CLIPS?


After working function, I get a number of fact, for example: Fact 2. How can I get information about this fact programmatically?


Solution

  • CLIPS> (clear)
    CLIPS> (deftemplate person (slot name) (slot address))
    CLIPS> (assert (person (name "Sam Jones") (address "123 Main Street")))
    <Fact-1>
    CLIPS> (assert (person (name "Sue Smith") (address "456 Maple Drive")))
    <Fact-2>
    CLIPS> (facts)
    f-0     (initial-fact)
    f-1     (person (name "Sam Jones") (address "123 Main Street"))
    f-2     (person (name "Sue Smith") (address "456 Maple Drive"))
    For a total of 3 facts.
    CLIPS> (fact-relation 2)
    person
    CLIPS> (fact-slot-value 2 name)
    "Sue Smith"
    CLIPS> (fact-slot-value 2 address)
    "456 Maple Drive"
    CLIPS>