'How do I set the initial value of an accumulator in KDB?
I've written a function r that represents a functional state s update, of the form s: r[s;q]
I'm trying to get it to scan a list of integers q, but the problem I'm getting is that the application of scan / consumes the first and second digits of the list, rather than the initial state s. The result should be a list of states.
What am I doing wrong?
Actual code:
a: 5+cos (til 20)
s: `peg`ent`exi!3#enlist[::]
r: {[s;q]
l: 0.9; h: 1.1;
init: `peg`ent`exi!({null x};{null x}; {null x});
s1: `peg`ent`exi!({not null x};{null x}; {null x});
s2: `peg`ent`exi!({not null x};{not null x}; {null x});
s: $[all init@'s; s, enlist[`peg]!enlist[q];s];
s: $[(all s1@'s) & q<l*s[`peg]; s, enlist[`ent]!enlist[q];s];
s: $[(all s2@'s) & q>h*s[`peg]; s, enlist[`exi]!enlist[q];s];
s
}
r scan a
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
