-1

Using the C API, how can I execute a CLIPS command in the context of a particular module? For example if I have defined a fact template in module FOO, how can I assert an instance of that fact? Evaluating (set-current-module FOO) doesn't cut it, if I do that and then evaluate (printout t (get-current-module) crlf) then I get the output MAIN

1 Answers1

0

I can't say what you did wrong since you didn't include any code, but using set-current-module works fine in both CLIPS 6.3 and 6.4.

Code for CLIPS 6.3:

int main(
  int argc,
  char *argv[])
  {
   void *theEnv;
   DATA_OBJECT theValue;

   theEnv = CreateEnvironment();

   EnvEval(theEnv,"(printout t (get-current-module) crlf)",&theValue); // Should be MAIN
   EnvBuild(theEnv,"(defmodule FOO)");
   EnvEval(theEnv,"(printout t (get-current-module) crlf)",&theValue); // Should be FOO
   EnvEval(theEnv,"(set-current-module MAIN)",&theValue);
   EnvEval(theEnv,"(printout t (get-current-module) crlf)",&theValue); // Should be MAIN
   EnvEval(theEnv,"(set-current-module FOO)",&theValue);
   EnvEval(theEnv,"(printout t (get-current-module) crlf)",&theValue); // Should be FOO

   DestroyEnvironment(theEnv); 

   return(-1);
  }

Code for CLIPS 6.4:

int main(
  int argc,
  char *argv[])
  {
   Environment *theEnv;

   theEnv = CreateEnvironment();

   Eval(theEnv,"(printout t (get-current-module) crlf)",NULL); // Should be MAIN
   Build(theEnv,"(defmodule FOO)");
   Eval(theEnv,"(printout t (get-current-module) crlf)",NULL); // Should be FOO
   Eval(theEnv,"(set-current-module MAIN)",NULL);
   Eval(theEnv,"(printout t (get-current-module) crlf)",NULL); // Should be MAIN
   Eval(theEnv,"(set-current-module FOO)",NULL);
   Eval(theEnv,"(printout t (get-current-module) crlf)",NULL); // Should be FOO

   DestroyEnvironment(theEnv);

   return -1;
  }
Gary Riley
  • 10,130
  • 2
  • 19
  • 34