I'm struggling to understand this q code programming idiom from the kx cookbook:
q)swin:{[f;w;s] f each { 1_x,y }\[w#0;s]}
q)swin[avg; 3; til 10]
0 0.33333333 1 2 3 4 5 6 7 8
The notation is confusing. Is there an easy way to break it down as a beginner?
I get that the compact notation for the function is probably equivalent to this
swin:{[f;w;s] f each {[x; y] 1_x, y }\[w#0;s]}
w#0
means repeat 0 w times (w
is some filler for the first couple of observations?), and 1_x, y
means join x, after dropping the first observation, to y. But I don't understand how this then plays out with f = avg
applied with each. Is there a way to understand this easily?