KDB / k: Functional form for creating 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" ...

transactions: CT [field name, types]

+4
source share
1 answer
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 a form of char types:

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

Source: https://habr.com/ru/post/1627647/


All Articles