Questions tagged [k]

k is an array processing language used in the kdb+ database. Do not use this tag for general kdb questions - only for questions pertaining to code in the k language.

K is an array processing language developed by Kx Systems. It is the foundation of the database used in financial products. K draws inspiration from APL and Scheme.

78 questions
2
votes
2 answers

Program memory footprint for different interpreters/compilers

Here's an excerpt from the Wikipedia entry on K programming language: The small size of the interpreter and compact syntax of the language makes it possible for K applications to fit entirely within the level 1 cache of the processor. What in…
Sergey Mikhanov
  • 8,880
  • 9
  • 44
  • 54
2
votes
1 answer

Using the K inside of KDB+ / Q and conditional branching specifically

I figure, to be a real KDB expert, I should learn K, right? So I can write some fast functions and understand how things actually work, etc.? I found this definition of factorial that does not work, even though it was an example in K-Lite Ref…
JSLover
  • 165
  • 1
  • 10
2
votes
2 answers

When is the EACH operator extension necessary in K besides mod/rotate?

In the K language, an operator can be suffixed with an apostrophe to apply to each element in an array: 8 +' 2 4 10 10 12 18 9 <' 3 10 2 0 1 0 8 -' 1 7 10 7 1 -2 However, in each of those cases, the apostrophe is not required, because these…
Ray Toal
  • 86,166
  • 18
  • 182
  • 232
2
votes
1 answer

how to create bulk object with char arrays for KDB+

I need to send bulks of K object to KDB via the C interface At the moment all my strings are sent as symbols which is not ideal. I would like to replace all symbols by standard char arrays For Symbols I did it this way // table_def:([] name:…
Pierre Lacave
  • 2,608
  • 2
  • 19
  • 28
2
votes
1 answer

Transform table by creating columns out of row groups

I have a table with time series data grouped by name (with some dates missing), and would like to transform the table by creating a column for each group containing that group's data. In other words, how do I go from this x:([]…
ScarletPumpernickel
  • 678
  • 1
  • 7
  • 22
1
vote
1 answer

KDB/Q How to implement moving rank efficiently?

I am trying to implement a moving rank function, taking parameters of n, the number of items, and m, the column name. Here is how I implement it: mwindow: k){[y;x]$[y>0;x@(!#x)+\:!y;x@(!#x)+\:(!-y)+y+1]}; mrank: {[n;x] sum each x > prev mwindow[neg…
S. Sun
  • 11
  • 2
1
vote
1 answer

Sum of each two elements using vector functions

How to get sum of eath two elements with the vector functions? I want the same result as: {x+y}':[1 2 3 2 1] Why this approach gives something different than first one? sum':[1 2 3 2 1]
egor7
  • 4,678
  • 7
  • 31
  • 55
1
vote
1 answer

A dictionary with a single value and multiple keys

What are the dictionaries with a single value and multiple keys stands for? What are their purposes? I've accidentally created one, but can not do anything with it: q)type (`a`b`c)!(`d) 99h q)((`a`b`c)!(`d))[`a] 'par
egor7
  • 4,678
  • 7
  • 31
  • 55
1
vote
1 answer

Getting table rows count by using count 1

To get an appropriate table rows count I thought to use a naive approach: use count 1 construct. And it works in a simple case: q)t:([]sym:`a`a`b`b); q)select cnt: count 1 by sym from t sym| cnt ---| --- a | 2 b | 2 But when I added other fields,…
egor7
  • 4,678
  • 7
  • 31
  • 55
1
vote
1 answer

Reshape [cols;table]

How do I get columns from a table? If they don't exist it's ok to get them as null columns. Trying reshape#: q)d:`a`b!1 2 q)enlist d a b --- 1 2 q)`a`c#d a| 1 c| q)`a`c#enlist d 'c [0] `a`c#enlist d ^ Why does thereshape# operator not…
egor7
  • 4,678
  • 7
  • 31
  • 55
1
vote
1 answer

Parse tree built on values from vars

We can group by several columns in kdb+: q)t:([]a:1 1 3;b:1 1 4;c:7 8 9); q)select sum c by grp:([]a;b) from t grp | c --------| -- `a`b!1 1| 15 `a`b!3 4| 9 q)gcols:`a`b But how to do the same with a functional form (how to build a correct…
egor7
  • 4,678
  • 7
  • 31
  • 55
1
vote
1 answer

Except (^ or _dvl) analog in k4, 8 Queens example

I've just played with 8 Queens puzzle, and found out that it seems there is no _dvl operator (from k(v2)) in k(v4). Also I checked other k versions from ngn k impls and found ^ operator in k(v6), for example at JohnEarnest's impl: l^a or l^l is…
egor7
  • 4,678
  • 7
  • 31
  • 55
1
vote
1 answer

Read file by its handle

q could create a file and read it content back in a nice way: q)`:foo 0: ("bar";"baz") `:foo q)`:foo 0:: "bar" "baz" https://code.kx.com/q/ref/read0/ says than one could use read0 to get data from file or process handle. But for some reason I could…
egor7
  • 4,678
  • 7
  • 31
  • 55
1
vote
1 answer

Define a view into non-default(current) namespace

According to How is a view defined Views and their dependencies can be defined only in the default namespace. Also q has a command \b: Syntax: \b [namespace] Lists dependencies (views) in namespace. Defaults to current namespace. According to…
egor7
  • 4,678
  • 7
  • 31
  • 55
1
vote
1 answer

Applying adverb to colon operator

Please help me with colon : operator, I'm stuck on how it works. It works as an assignment, assignment through x+:1, global assignment/view ::, I/O 0:, 1:, to return value from the middle of the function :r, and to get an unary form of operator…
egor7
  • 4,678
  • 7
  • 31
  • 55