2

How can I get value to see a variable in a local scope? For example:

a:2;

func:{
  a:1;
  value "a"
 }

returns 2

4
  • 1
    You shouldn't ever need to use value (or even eval) like this. There would be better/cleaner ways to do it. A more comprehensive real-life example might help Commented Feb 5, 2015 at 15:20
  • I have a function that takes a list of functions that update new columns onto a table. The cleaner way to do it is with a functional update, but I came across this issue while finding an alternative to that very ugly syntax. Commented Feb 5, 2015 at 19:45
  • 1
    Some people would say that that very ugly syntax is beautiful! But sometimes functional form is just necessary, and arguably less ugly than generating stringified lines of code to be evaluated. One way to use functional form while still retaining some user-friendly readability is to use something similar to Aaron Davies' "semi-functional" forms. See q-ist.com/2012/10/functional-query-functions.html and q-ist.com/2013/03/my-kdb-user-meeting-presentation.html Commented Feb 5, 2015 at 22:00
  • Absolutely :) I use functional select in my rdb/hdb gateway process, but in this particular instance, it was easier just to stringify a little bit of code, and then I got to learn a little more about value by posting this question! Thanks for sharing Aaron's articles, I've referenced many things he has posted Commented Feb 5, 2015 at 23:36

2 Answers 2

2

value will always work on global scope.

If you really need this, maybe make use of workspace variables, e.g. .a.b:1 ... I don't have a q instance to hand to test if that works but i'm almost sure it does.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use other function instead of 'value'. One option is 'eval' function:

        q)a:2;

        q) func:{ a:1; eval a}
        q)  func[]
        q) 1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.