1

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.

4

1 に答える 1

1

ファクト クエリ関数を使用して、ファクト リストをクエリし、アクションを実行できます。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);

最初の呼び出しでは、値が 1 のピザ ファクトのみが取り消されます。2 番目の呼び出しでは、すべてのカリフラワー ファクトが撤回されます。

于 2012-05-31T19:36:07.870 に答える