Fail to call the each function in DolphinDB due to the error Cannot recognize the token a

11 Views Asked by At

The script below triggers the error Cannot recognize the token a. How to modify this script?

a = `a`b`c
each(i -> each(add{i,}, a), 1..10)
1

There are 1 best solutions below

0
On

In your script, the function each(add{i,}, a) references the external variable a, which is not an input parameter. Since a function cannot reference external variables, an error is triggered. You can modify the script as follows:

a = `a`b`c
def f(i, a):each(add{i,}, a)
each(f{,a}, 1..10)