zrb
zrb

Reputation: 891

KDB/k: Functional form to create a table variable

Is there a functional form equivalent to the following?

trades:([]date:`date$();time:`time$();sym:`symbol$();price:`real$();size:`int$(); cond:`char$())

Assuming the function name is "ct"...

trades:ct[fieldNames;types]

Upvotes: 4

Views: 337

Answers (1)

MdSalih
MdSalih

Reputation: 1996

ct:{[fields;types] flip fields!types$\:()}

Example:

q)ct[`date`time`sym`price`size`cond;`date`time`symbol`float`long`symbol]
    date time sym price size cond
    -----------------------------

Will also work with char form of types:

q)ct[`date`time`sym`price`size`cond;"dtsfjs"]
    date time sym price size cond
    -----------------------------

Upvotes: 4

Related Questions