如何获取此变量的值

时间:2022-01-06 20:53:34

I am making an app with Clips as expert system. I was wondering if it is possible to collect the value of the ?result variable, or how to execute a piece of code and then get the result.

我正在使用Clips作为专家系统制作应用程序。我想知道是否有可能收集?result变量的值,或者如何执行一段代码然后得到结果。

- (void)viewDidLoad {
    [super viewDidLoad];
    clipsEnv = CreateEnvironment();
    if (clipsEnv == NULL) return;

    DATA_OBJECT theDO;
    EnvEval(clipsEnv,"(bind ?result (numberp (member$ 'Yes' (create$ 'Yes' ))))",&theDO);

}

What I put above is an example. My application uses a large .clp, I can not eliminate the variable because it is used to make other calculations.

我上面提到的是一个例子。我的应用程序使用大的.clp,我无法消除变量,因为它用于进行其他计算。

For example I want to keep ?totalDays ?inputDays and ?variableResultado without modifying any code.

例如,我想保留?totalDays?inputDays和?variableResultado而不修改任何代码。

(bind ?totalDays (+ (* (nth$ 1 (GetDate)) 365)(* (nth$ 2 (GetDate)) (/ 365 12))(nth$ 3 (GetDate))))(bind ?inputDays (+ (* (- (Decimal (sub-string 7 10 ?FechaNacimiento)) 1900) 365)(* (Decimal (sub-string 4 5 ?FechaNacimiento)) (/ 365 12))(Decimal (sub-string 1 2 ?FechaNacimiento))))(bind ?variableResultado (* (/ (- ?totalDays ?inputDays) 365) 12))

2 个解决方案

#1


0  

You don't need to bind the return value of a function to a variable to retrieve it using EnvEval:

您不需要将函数的返回值绑定到变量以使用EnvEval检索它:

void *clipsEnv;
DATA_OBJECT theDO;
const char *theString;

clipsEnv = CreateEnvironment();

EnvEval(clipsEnv,"(numberp (member$ 'Yes' (create$ 'Yes' )))",&theDO);
theString = DOToString(theDO);

#2


0  

Answering my own question. One possible solution is to define a global variable in a external file instead of a ordinary variable, and then get the result with EnvFindDefglobal() and EnvGetDefglobalValue().It's one of the possible ways I've found.

回答我自己的问题。一种可能的解决方案是在外部文件中定义全局变量而不是普通变量,然后使用EnvFindDefglobal()和EnvGetDefglobalValue()获取结果。这是我找到的可能方法之一。

clipsEnv = CreateEnvironment();
EnvReset(clipsEnv);

if (clipsEnv == NULL){
     string = @"Error";
    return string;
}

filePath = [[NSBundle mainBundle] pathForResource: @"try" ofType: @"clp"];
cFilePath = (char *) [filePath UTF8String];
EnvLoad(clipsEnv,cFilePath);
DATA_OBJECT theDO;
EnvFindDefglobal(clipsEnv, "?*variable*");
EnvGetDefglobalValue(clipsEnv, "variable", &theDO);
string = [NSString stringWithUTF8String:ValueToString(GetValue(theDO))];
return string;

In the try.clp file:

在try.clp文件中:

(bind ?result (numberp (member$ 'Yes' (create$ 'Yes' )))); (defglobal ?*variable* = ?result);

(bind?result(numberp(member $'Yes'(create $'Yes')))); (defglobal?*变量* =?结果);

#1


0  

You don't need to bind the return value of a function to a variable to retrieve it using EnvEval:

您不需要将函数的返回值绑定到变量以使用EnvEval检索它:

void *clipsEnv;
DATA_OBJECT theDO;
const char *theString;

clipsEnv = CreateEnvironment();

EnvEval(clipsEnv,"(numberp (member$ 'Yes' (create$ 'Yes' )))",&theDO);
theString = DOToString(theDO);

#2


0  

Answering my own question. One possible solution is to define a global variable in a external file instead of a ordinary variable, and then get the result with EnvFindDefglobal() and EnvGetDefglobalValue().It's one of the possible ways I've found.

回答我自己的问题。一种可能的解决方案是在外部文件中定义全局变量而不是普通变量,然后使用EnvFindDefglobal()和EnvGetDefglobalValue()获取结果。这是我找到的可能方法之一。

clipsEnv = CreateEnvironment();
EnvReset(clipsEnv);

if (clipsEnv == NULL){
     string = @"Error";
    return string;
}

filePath = [[NSBundle mainBundle] pathForResource: @"try" ofType: @"clp"];
cFilePath = (char *) [filePath UTF8String];
EnvLoad(clipsEnv,cFilePath);
DATA_OBJECT theDO;
EnvFindDefglobal(clipsEnv, "?*variable*");
EnvGetDefglobalValue(clipsEnv, "variable", &theDO);
string = [NSString stringWithUTF8String:ValueToString(GetValue(theDO))];
return string;

In the try.clp file:

在try.clp文件中:

(bind ?result (numberp (member$ 'Yes' (create$ 'Yes' )))); (defglobal ?*variable* = ?result);

(bind?result(numberp(member $'Yes'(create $'Yes')))); (defglobal?*变量* =?结果);