'Are side-effects sometimes necessary when using KDB?

Let's say I have a state variable s.

I've got a .z.ws hook that responds to websocket messages and runs:

.z.ws: {handleMsg x}

Do I have to declare s as global for handleMsg to be able to update s?

Ideally, what I'd want is something like:

s: handleMsg[s;x]

where handleMsg is a pure function (it doesn't affect any globals on the inside).

Should I declare s as global and then try to do this assignment inside the websocket callback?

kdb


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source