CLIPS 使用 EnvEval 和 find-fact 命令在 FlushMultifields() 中冻结

CLIPS freezes in FlushMultifields() with EnvEval and find-fact command

我在使用 CLIPS 时遇到了一个奇怪的问题,很难调试。 我有以下事实清单:

f-0     (initial-fact)
f-1     (SpinWave (quantum_number_names "charge" "isospin" "spin" "parity" "cparity") (quantum_number_values 0 1 2 -1 -1))
f-2     (SpinWave (quantum_number_names "charge" "isospin" "spin" "parity" "cparity") (quantum_number_values 0 1 3 -1 -1))
f-3     (SpinWave (quantum_number_names "charge" "isospin" "spin" "parity" "cparity") (quantum_number_values 0 1 4 -1 -1))
f-4     (SpinWave (quantum_number_names "charge" "isospin" "spin" "parity" "cparity") (quantum_number_values 0 3 1 -1 1))
f-5     (ViolatingRulesForDecay (list_of_violated_rules))
f-6     (SpinQuantumNumber (unique_id 1) (numerator 0) (denominator 1) (z_component_numerator 0))
f-7     (SpinQuantumNumber (unique_id 2) (numerator 1) (denominator 1) (z_component_numerator -1))
f-8     (SpinQuantumNumber (unique_id 3) (numerator 1) (denominator 1) (z_component_numerator 0))
f-9     (SpinQuantumNumber (unique_id 4) (numerator 1) (denominator 1) (z_component_numerator 1))
f-10    (SpinQuantumNumber (unique_id 5) (numerator 2) (denominator 1) (z_component_numerator -2))
f-11    (SpinQuantumNumber (unique_id 6) (numerator 2) (denominator 1) (z_component_numerator -1))
f-12    (SpinQuantumNumber (unique_id 7) (numerator 2) (denominator 1) (z_component_numerator 0))
f-13    (SpinQuantumNumber (unique_id 8) (numerator 2) (denominator 1) (z_component_numerator 1))
f-14    (SpinQuantumNumber (unique_id 9) (numerator 2) (denominator 1) (z_component_numerator 2))
f-15    (AllowedQuantumNumbers (name "spin") (values 1 2 3 4 5 6 7 8 9))
f-16    (AllowedQuantumNumbers (name "isospin") (values 1 2 3 4))
f-17    (AllowedQuantumNumbers (name "charge") (values -1 0 1))
f-18    (AllowedQuantumNumbers (name "parity") (values -1 1))
f-19    (AllowedQuantumNumbers (name "cparity") (values -1 1))
For a total of 20 facts.

我试图在 C++ 中搜索其中一个事实,我通过以下方式进行:

DATA_OBJECT found_spin_quantum_number_facts;
std::stringstream clips_query;
clips_query << "(find-fact ((?f SpinQuantumNumber)) 
(and (= ?f:numerator " << spin_state.J_numerator_ << ") (and (= 
?f:denominator " << spin_state.J_denominator_ << ") (= 
?f:z_component_numerator " << spin_state.J_z_numerator_ << "))))";

std::cout << clips_query.str() << std::endl;
EnvEval(clips_environment_, clips_query.str().c_str(),
  &found_spin_quantum_number_facts);

它工作了好几次,直到它用下面的 clips 表达式中断(这对我来说似乎是合法的,并且工作了好几次,直到它失败):

(find-fact ((?f SpinQuantumNumber)) (and (= ?f:numerator 0) (and (= ?f:denominator 1) (= ?f:z_component_numerator 0))))

find-fact 函数实际上完成了执行,但是在 FlushMultifields() 函数中剪辑卡住了...我错过了什么?提前致谢!

史蒂夫

所以我一直在调试它,正如 Gary 提到的那样,问题完全出在其他地方。我用一个地址断言一个事实,该地址已经指向一个现有的事实(可以说在事实堆栈上)。不知道当时在想什么...

void* ifs_template = EnvFindDeftemplate(clips_environment_,
  "InitialAndFinalState");
void* ifs_fact = EnvCreateFact(clips_environment_, ifs_template);
if (ifs_fact != NULL) {
  DATA_OBJECT field;
  field.type = FACT_ADDRESS;

  OLD-CODE: field.value = EnvAssert(clips_environment_,
    addSpinWaveToClipsEnvironment(initial_state));
  NEW-CODE: field.value = 
    addSpinWaveToClipsEnvironment(initial_state);
  EnvPutFactSlot(clips_environment_, ifs_fact, "initial_state", &field);

addSpinWaveToClipsEnvironment() 函数创建一个新的 SpinWave 事实(如果不存在),并且 returns 该事实的地址。