My code might have facts such as:
(assert (person "Jack")) (assert (fruit "apple"))
I would like to print for example the person if only it exists such as
The person is "Jack"
I tried using this condition
(if (find-fact ((?f person)) TRUE) then (printout t "The fact exists." crlf) )
but if the person relation does not exist, it shows an error. I do not want to see anything or error if the fact does not exist. Is this possible
Thank you.
Assuming the error you get is the following:
The reason is you are using an ordered fact. Ordered facts do not have associated
deftemplates, hence the error. CLIPS creates an implicitdeftemplatewhenever a new fact of a give type is created. This is why you see thefind-factfunction working if thepersonfact is asserted.The best solution, would be to use
deftemplatefacts instead of ordered ones. In this way, the engine knows beforehand which types of fact exist and can use this information to build its internal queries.