r/kdb • u/[deleted] • Dec 13 '19
How to modify variable referenced by symbol inplace?
So I have a dictionary and I want another function to modify that dictionary. The function does not know the name of that dictionary a priori. Since q doesn't have lexical scoping (which is a huge letdown, btw), I have to pass in a symbol. But I can only get/set that symbol, I can't modify the dictionary in place. I could first get the dictionary, assign it to a variable, change the dictionary, and the set it back to the symbol, but it involves unnecessary copying. Is there a solution to this?
2
Upvotes
1
u/rocketship92 Dec 14 '19
If I understand the question correctly then you can just use
@apply to modify the dictionary in place. For example the following function takes a dictionary and a key to update: