2021.11.20 06:12 AM
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?
2021.11.20 12:02 PM
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
2021.11.20 07:45 AM - edited 2021.11.20 07:46 AM
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'.
2021.11.20 12:02 PM
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
2021.11.20 11:16 PM
very clear explanation! Thanks!
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.