AI Zone Admin Forum Add your forum

NEWS: survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Dynamic generation of macro name

Hi, is it possible to gernerate the name of a macro at runtime (e.g. with ^join using variables) and execute it?

outputmacro: ^testmacro()
testmacro success 

and then do

u: (test macroexecuting macro \n
$$_test = ^join(\testmacro \\) ) 

i tried ^eval() and
^$$_test indirection but without success.


  [ # 1 ]

It is not currently possible to bypass the script compiler when writing executable code like your function call.
I will think about how I would enable it.


  [ # 2 ]

I have done it, but it is not the most obvious or cleanest, and did require me to step through the engine in VS to work it out.


  [ # 3 ]


Would you share your solution? I want to do the same kind of thing. I have created a macro called
^iterateRejoinders( ^topRule ^funToExecute )

The purpose is to execute the given function against the direct descendants of the given rule, skipping all of the other rejoinders that may occur before the next official topRule.

Everything is working fine but

$$_funcall = ^join\^ ^funToExecute \( $$_curRule \) )
nofailRULE ^eval( $$_funcall) 

results in


rather than the output of the ^printRule function.

a trace on the code reveals:

System call ^join(`\^ ^1 \( $$_currule \)`)
.NOPROBLEM ^join(\^ ^1 \( $$_currule \)) => `^printRule(~test-options.7.3)`
$$_funcall = ^join(^printRule(~test-options.7.3))
System call ^nofail(`RULE ^eval ( $$_funcall )`)
.System call ^eval(`$$_funcall`)
..NOPROBLEM ^eval(^printRule(~test-options.7.3)) => `^printRule(~test-options.7.3)`
.NOPROBLEM ^nofail(RULE ^eval ( $$_funcall )) => `^printRule(~test-options.7.3)`



  [ # 4 ]

OK, something like:

$_func = ^join(\^ $_functionName \( $_arg \) )

That creates the basic string that represents the function call, but for the engine to process it correctly then you have to add another level of indirection:

$_cmd = ^”\”^$_func\”“

Then final command is:

I’ve often wrapped that in a ^result() or used RESPONSE_NONE as the first parameter of the ^eval().


  [ # 5 ]

per release notes for 8.5

7. indirect function call ^$_xx()  if $_xx holds a function name


  [ # 6 ]

Thanks Bruce,

I will give it a try. It would be nice to have an iterator/callback pattern.


  [ # 7 ]

give me an example of what you want.  Callbacks of the non-sequential calling sequence will not happen, we dont run multiple threads in the engine. As for iterators, there already are some iterators. ^readfromfile is a kind of iterator. And boring loops can be used to iterate on things.


  login or register to react