AI Zone Admin Forum Add your forum

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

Functionality of ^eval()
 
 

The description from ^eval in the documentation:

  to evaluate a stream as though it were output (like to assign a
variable)

From this I would expect it to replace variable names with their content anywhere in the stream.
But I tested this is only working with if the stream contains only the variablename and no other output.
So

t$replace=^"\$tobereplaced
$tobereplaced=testcontent
^eval($replace) 

works,

t$replace=^"some variable: \$tobereplaced
$tobereplaced=testcontent
^eval($replace) 

or

t$replace=^"\$tobereplaced will not be replaced" 
$tobereplaced=testcontent
^eval($replace) 

not.
Is this the inteded behavior?
If so no problem, I think I can write code to find all variable names and copy them to a substring, evaluate them and copy them back.
But if not I don’t have to write this code and can do this just with a single call of ^eval

 

 
  [ # 1 ]

3 comments embedded in this illustration

u: (test)
$tobereplaced = testcontent
$replace = ^”$tobereplaced will not be replaced”
^eval($replace)

a) separate your tokens in outputdata. Dont do x=y, use x = y.

b) an active string like ^”$tobereplaced will not be replaced”  ACTS THE INSTANT YOU USE IT. It does not wait til later. So it acts when assigned onto $replace. You need to change your order of assignment. 

c) given b, there is no merit in calling ^eval.  It is already evaled.

 

 
  [ # 2 ]

You got me a little bit wrong.

This is just an example which in this case doesn´t make much sence, but I have to define the variables in this order in my situation. This is just a simplified piece of code to explain my situation.

So I want to wait til later. The insertion of the variable is a placeholder, thats why I am escaping the $-charakter.
I am aware of a) now, thanks, but my problem is still open.

A string like “$replace” works with ^eval, “abc $replace” or “$replace abc” not.

 

 
  [ # 3 ]

So I’m still not understanding. “From this I would expect it to replace variable names with their content anywhere in the stream. But I tested this is only working with if the stream contains only the variablename and no other output.”
As far as I’m thinking, eval will do mixed variablename and other output, as will a simple active string directly

 

 
  [ # 4 ]
Bruce Wilcox - May 1, 2016:

As far as I’m thinking, eval will do mixed variablename and other output, as will a simple active string directly

^eval seems to be buggy for me, if it should be the same as an active string.

outputmacro: ^innerFunc()
  this is the intended output

topic: ~introductions []
u: (testschedule1) ^”^innerFunc()” # this is working
u: (testschedule2) ^eval(”^innerFunc()”) # this is just printing “innerFunc()”
                                                              # without quotes

 

 
  [ # 5 ]

eval is not intended to be similar to an active string. eval is simply the entire normal output processor.  An active string is a limited subset intended as a format string with embedded variables to be converted and does not do [] optional choices.

“xxx”  is not an active string. ^“xxxx”  is. hence ^eval(”^innerFunc()”)  is simply printing the string you requested be printed

 

 
  [ # 6 ]
Bruce Wilcox - May 19, 2016:

eval is not intended to be similar to an active string. eval is simply the entire normal output processor.  An active string is a limited subset intended as a format string with embedded variables to be converted and does not do [] optional choices.

“xxx”  is not an active string. ^“xxxx”  is. hence ^eval(”^innerFunc()”)  is simply printing the string you requested be printed

So is there a possibility to call a function which is represented in a string in a variable somehow?

i have

$$function = “^innerFunc()”


and I want to execute it somewhere else in the code at another point?

 

 
  [ # 7 ]

u: (try)  $var = ^” ^myfunc() ”  set
u: (it)  ^eval($var)

 

 
  [ # 8 ]

In this case ^myfunc() is executed in the (try)-rule, isn´t it?
I want it to be executed in the (it)-rule

 

 
  [ # 9 ]

right. Direct assignment of such to a variable does not work at present.

 

 
  login or register to react