Grant Baker
Grant Baker

Reputation: 11

in Kdb, how do I assign a list of symbols each to a list of values

For example, I want to pass a dictionary with 10 pairs into a function to bypass the 8 valence limit. I then want the keys of the dictionary each to be assigned as a local variable to be assigned to their value and use that as the parameters for my function. Alternatively, is there a better way to pull this off?

Upvotes: 1

Views: 284

Answers (1)

Anton Dovzhenko
Anton Dovzhenko

Reputation: 2569

I am afraid there is no way to functionally assign value to local scope variable. E.g.

{eval parse "a: 10";}1b 

creates global variable a.

You may fix some scope name, e.g. .l, keep variables there and clear scope before function return, e.g.:

{
  eval each (:),'flip (`$".l.",/:string key x;value x);
  r: .l.a + .l.b + .l.c;
  delete from `.l;
  r
}`a`b`c!1 2 3

But getting values directly from input dictionary (like x[`a]) seems easier and clearer approach.


apply helps to simplify invoking other functions, using dictionary values as parameters. This may be what you are looking for. E.g.

{
  f: {x+y+z};
  f . x`a`b`c
}`a`b`c!1 2 3

Upvotes: 3

Related Questions