cancel
Showing results for 
Search instead for 
Did you mean: 

How can I replicate "each til count subs"

mamsds
New Contributor II

I am studying a sample from official KDB repo: (https://github.com/kxcontrib/websocket/blob/master/AppendixB/pubsub.q) . There is a line (https://github.com/kxcontrib/websocket/blob/ad2f0b268afaee1fc5f4dda2fc2467440c7e2f0c/AppendixB/pubsu...) . My overall understanding is that we call function pub with parameters generated by each til count subs . However, while I try to replicate the result from each til count subs in a q console, I get an error as attached. 

My question is, how I can replicate the parameters generated from each til count?

1 ACCEPTED SOLUTION

rocuinneagain
Valued Contributor
Valued Contributor
q)tab:([] a:`a`b`c;b:1 2 3) //Create a table
q)tab 0 //Index in to the table to row 0. A dictionary is returned
a| `a
b| 1
q)til 3
0 1 2
q)count tab // tab contains 3 rows
3
q)til count tab // 'til' returns numbers up to entered value
0 1 2
q){show tab x}each til count tab //Using 'each' and 'show' in a lambda to display each row
a| `a
b| 1
a| `b
b| 2
a| `c
b| 3

View solution in original post

3 REPLIES 3

rak1507
New Contributor III

Each is an iterator/adverb - what that line does is applies pub to each item of 'til count subs', not applying pub to 'each til count subs'.

rocuinneagain
Valued Contributor
Valued Contributor
q)tab:([] a:`a`b`c;b:1 2 3) //Create a table
q)tab 0 //Index in to the table to row 0. A dictionary is returned
a| `a
b| 1
q)til 3
0 1 2
q)count tab // tab contains 3 rows
3
q)til count tab // 'til' returns numbers up to entered value
0 1 2
q){show tab x}each til count tab //Using 'each' and 'show' in a lambda to display each row
a| `a
b| 1
a| `b
b| 2
a| `c
b| 3

very clear explanation! Thanks!