# Value in function scope

**URL:** <https://forum.kx.com/t/value-in-function-scope/12062>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [September 24, 2020, 4:58pm UTC](https://forum.kx.com/t/value-in-function-scope/12062 "2020-09-24T16:58:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![newstudent20171](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@newstudent20171](https://forum.kx.com/u/newstudent20171)\
**Post date:** [September 24, 2020, 4:58pm UTC](https://forum.kx.com/t/value-in-function-scope/12062/1 "2020-09-24T16:58:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![matt\_moore1](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@matt\_moore1](https://forum.kx.com/u/matt_moore1)\
**Post date:** [September 24, 2020, 7:34pm UTC](https://forum.kx.com/t/value-in-function-scope/12062/2 "2020-09-24T19:34:00Z")

</div>

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&nbsp;https://code.kx.com/q/ref/vs/&nbsp;

---

<div class="post-metadata">

**Author:** ![Flying1](https://avatars.discourse-cdn.com/v4/letter/f/f4b2a3/32.png) [@Flying1](https://forum.kx.com/u/Flying1)\
**Post date:** [September 25, 2020, 7:55am UTC](https://forum.kx.com/t/value-in-function-scope/12062/3 "2020-09-25T07:55:00Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![SJT1](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@SJT1](https://forum.kx.com/u/SJT1)\
**Post date:** [September 25, 2020, 9:05am UTC](https://forum.kx.com/t/value-in-function-scope/12062/4 "2020-09-25T09:05:00Z")

</div>

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
