c++ - CLIPS eval stops working if fact does not exist -


i using clips api enveval in order find fact given relation:

auto expression = "(find-all-facts ((?f system)) true)";  data_object outputvalue;  auto res = enveval(penvironment, expression, &outputvalue); return res; 

but problem if try find fact not exist in current list of facts, enveval return false facts exist, each single new call.

why behavior , doing wrong?

your source code partial , not know if understand situation correctly.

but, anyway, here's working quick hack, according problem, might help.

ps: clips stable, documented , updated (thanks gary).

(compiled clang , gcc under linux)

file: sample.clp

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

c code

#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 evaluated\n");   } else {      /* print result of find-all-facts field field */     if (gettype(outputvalue) == multifield) {        end = getdoend(outputvalue);       multifieldptr = getvalue(outputvalue);       envprintrouter(theenv,wprompt,"( ");       (i = getdobegin(outputvalue); <= 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 multifield!");     }    }    return(0); } 

when compile , run get

( <fact-4> <fact-6> <fact-7> ) 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -