Problem related to local variables

Hi everyone,

I’m working on function calling and encountered some problem. To put it in a simple way, say I have a function f looks like

f:{[a;b] …}

and inside f another function g is called to get the name of a third function h, let’s call it handle.

Then I intend to use eval parse to call function h, which also takes input parameter a and b as f does.

eval parse “result:”, handle,“[a;b]”

Unfortunately the above doesn’t work. I manage to find out that eval parse works only with global variables, and “value” and “get” work similarly as eval parse in this situation.

Do I understand the mechanism of eval parse, value and get correctly? Is there a way to get around this so I can work with local variables in a string?

Much appreciated,
Michael He

There is no need for an eval call here.

You can return a function directly from g and call it. (Note: functions are just normal “data” that can be passed around like other data types.)

q)h:+q)g:{$[x=plus;h;*]}q)f:{[x;y] g[plus][x;y]}q)f[10;20]30

Alternatively, you can directly involve a function using its symbolic name, too:

q)h:+q)error:{[x;y]'"error"}q)g:{$[x=plus;h;error]}q)f:{[x;y] g[plus][x;y]}q)f[10;20]30

In any case above, you don’t need an eval call at all.