Value in function scope

I am trying to split strings.

In global scope it works :

arg:“abc def”
i:arg?" "
value “0 “,string[i],” _ arg”

Output
(“abc”;" def")

However in function scope

{i:x?" “; value"0 “,string[i],” _ x”} [arg]

I get the error message x

Question:

How to make value execute in function scope

value doesn’t work in function scope because it is looking for the global variable x;

q)x:arg

q){i:x?" “; value"0 “,string[i],” _ x”} [arg]

“abc”

" def"

However, there is a better way to do this using vs (vector from scalar):

q)arg

“abc def”

q)" " vs arg

“abc”

“def”

See https://code.kx.com/q/ref/vs/ 

The evaluation of value does not see local variables in the function. Why not simply use a function for this purpose? 

{(0;x?" ")_ x} arg

Or if the original problem is, as stated, to split a string, use vs

q)" " vs “abc def”
“abc”
“def”

https://code.kx.com/q/ref/vs




Stephen Taylor | Librarian | Kx | +44 7713 400852 | stephen@kx.com