如果事实不存在,CLIPS eval将停止工作

时间:2016-11-10 14:46:08

标签: c++ clips

我正在使用CLIPS API EnvEval,以便根据其关系找到一个事实:

auto expression = "(find-all-facts ((?f system)) TRUE)";

DATA_OBJECT outputValue;

auto res = EnvEval(pEnvironment, expression, &outputValue);
return res;

但我的问题是,如果我试图找到当前事实列表中不存在的事实,对于每个新的呼叫,EnvEval将始终返回FALSE,即使对于确实存在的事实也是如此。 / p>

为什么这种行为以及我做错了什么?

1 个答案:

答案 0 :(得分:1)

您的源代码非常偏微,我没有 知道我是否正确了解情况。

但是,无论如何,这是一个快速入侵的工作 你的问题,这可能会有所帮助。

PS:CLIPS非常稳定,记录和更新(感谢Gary)。

(在linux下使用clang和gcc编译)

file:sample.clp

0  
0  // Isn't T decayed to std::array<int, 2> ?
0

C代码

(deffacts dummy-example ""
  (not-important blá)
  (dummy foo)
  (useless bar)
  (my-system aaa)
  (just-noise bbb)
  (my-system bbb)
  (my-system ccc))

当你编译并运行时,你得到

#include "clips.h"

int main(/* int argc, char *argv[] */)
{
  void *theEnv;
  char *expression;
  DATA_OBJECT outputValue;
  char *result;

  void *multifieldPtr, *factPtr;
  long end, i;

  theEnv = CreateEnvironment();

  EnvLoad(theEnv, "sample.clp");
  EnvReset(theEnv);
  EnvRun(theEnv, -1);

  expression = strdup("(find-all-facts ((?f my-system)) TRUE)");

  if (!EnvEval(theEnv, expression, &outputValue)) {
    EnvPrintRouter(theEnv, WPROMPT,
                   "NOT successfully evaluated\n");
  } else {

    /* Print the result of find-all-facts field by field */
    if (GetType(outputValue) == MULTIFIELD) {

      end = GetDOEnd(outputValue);
      multifieldPtr = GetValue(outputValue);
      EnvPrintRouter(theEnv,WPROMPT,"( ");
      for (i = GetDOBegin(outputValue); i <= end; i++){
          if (GetMFType(multifieldPtr,i) == FACT_ADDRESS){
            factPtr = GetMFValue(multifieldPtr,i);
            asprintf(&result,"<Fact-%lld> ",
                     EnvFactIndex(theEnv, factPtr));
            EnvPrintRouter(theEnv,WPROMPT,result);
          }

      }
      EnvPrintRouter(theEnv,WPROMPT,")\n");
    } else {
      EnvPrintRouter(theEnv,WPROMPT,"Not a multifield!");
    }

  }

  return(0);
}
相关问题