Yes, that is how I have it done now but it is a bit ugly ;-). And isn't there any way to get this information using a user defined function? Isn't there any "pointer" to the actual rule body, etc.?
Thanks Vranoch
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Create a user-defined function and include engine.h in your source file. You can then use the macro
EngineData(theEnv)->ExecutingRule
to reference the executing rule. The argument to the macro is a pointer to the environment, which if you write an environment aware user function will be passed into it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, is there a chance to get a name of a defrule within its body?
(defrule XY
=>
(printout t "NAME: " (get-defrule-name ) crlf)
)
thanks Vranoch
No, you would have to hardcode the rule name.
Yes, that is how I have it done now but it is a bit ugly ;-). And isn't there any way to get this information using a user defined function? Isn't there any "pointer" to the actual rule body, etc.?
Thanks Vranoch
Create a user-defined function and include engine.h in your source file. You can then use the macro
EngineData(theEnv)->ExecutingRule
to reference the executing rule. The argument to the macro is a pointer to the environment, which if you write an environment aware user function will be passed into it.
Thanks Gary, that is exactly what I searched. For others:
userfunctions.h:
long int xActualRule(void *theEnv, DATA_OBJECT_PTR returnValuePtr);
userfunctions.c:
long int xActualRule(void *theEnv,
DATA_OBJECT_PTR returnValuePtr)
{
if (EnvArgCountCheck(theEnv,"kmx-actual-rule",EXACTLY,0) == -1)
{ return(-1L); }
SetpType(returnValuePtr,STRING);
if (NULL != EngineData(theEnv)->ExecutingRule)
SetpValue(returnValuePtr, EnvAddSymbol (theEnv, EnvGetDefruleName(theEnv, &(EngineData(theEnv)->ExecutingRule->header))));
else
SetpValue(returnValuePtr, "");
return 0L;
}
void InitializeUserFunction(void *theEnv)
{
EnvDefineFunction2(theEnv,"x-actual-rule", 'k', PTIEF xActualRule, "xActualRule", "00s");
}
test.clp:
(defrule XY ""
=>
(printout t "RULE: >" (x-actual-rule ) "<" crlf)
)
Thanks for the code!!
It works great!