Question

I am working with CLIPS embedded in a C program, so I have to do everything by C function calls and can't use the CLIPS command line.

Let's say I have asserted a few facts like this:

AssertString("(pizza 1)");
AssertString("(cauliflower 7)");
AssertString("(cheesecake 0)");

Obviously I do not get (let alone retain) any pointers to my facts at this point. When I want to retract a fact later by using Retract(factPtr), I obviously need the pointer to the fact I want to retract. So, after the lines above, how would I find the fact (cauliflower 7) again and get a pointer to it?

Do I have to get the entire fact list by GetFactList([...]), loop through it and compare strings? If so, how would I do that in the multifield DATA_OBJECT this function returns? Or is there a better way?

I would be grateful for any ideas or even code examples.

Was it helpful?

Solution

You can use the fact query functions to query the fact-list and perform actions. You can invoke this through the EvalFunction:

DATA_OBJECT result;

Eval("(do-for-all-facts ((?f pizza)) (eq ?f:implied (create$ 1)) (retract ?f))",&result);
Eval("(do-for-all-facts ((?f cauliflower)) TRUE (retract ?f))",&result);

In the first call, only the pizza fact with the value 1 is retracted. In the second call, all cauliflower facts are retracted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top