cancel
Showing results for 
Search instead for 
Did you mean: 

Value in function scope

newstudent2017
New Contributor II

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
3 REPLIES 3

matt_moore
New Contributor III
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/ 



Flying
New Contributor III
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

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

q)" " vs "abc def"
"abc"
"def"





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