From Kx Wiki
Jump to: navigation, search


 ! internal function

! with a negative integer on the left hand side, calls a k internal function.

Warning.png -n! bindings are subject to change, if a cover function is provided in the .q or .Q locales use that instead!
Neal Stephenson thinks it's cute to name his labels 'dengo'

these should rarely, if ever, be used, but since it is useful to be able to recognise them when seen in the wild, here is a partial list:


see/use hsym


see/use attr


returns the string representation of x.

strictly this is .Q.s1, but it's better to use .Q.s


returns the list of q tokens found in string x (note the q parsing of names with embedded underscores)

q)-4!"select this from that"
," "
," "
," "

q)-5!"select this from that" / compare with −5!

q)-4!"a variable named aa_bb"
," "
," "
," "


see/use parse


see/use eval


see/use hcount


return the IPC byte representation of x

q)-8!1 2 3


create data from IPC byte representation x

q)-9!-8!1 2 3
1 2 3
Warning.png don't hand knit your own bytestreams …


resolve a type number to an enum vector and check if it's available

q)type vv


streaming execute over file x, used for example in kdb+tick to replay logfiles in a memory efficient manner.

A logfile is just a list of lists, and each list is read in turn and executed (see value) either via value or if it is defined.

Here, for demonstration purposes, we manually create a logfile, and play it back through -11. This is functionally equivalent to doing "value each get`:logfile" but using far less memory.

q)`:logfile.2013.12.03 set () / create a new,empty log file
q)h:hopen `:logfile.2013.12.03 / open it
q)h enlist(`f;`a;10) / append a record
q)h enlist(`f;`b;20) / append a record
q)hclose h / close the file
q)f:{0N!(x;y)} / define the function that is referenced in those records
q)-11!`:logfile.2013.12.03 / playback the logfile
q)value each get `:logfile.2013.12.03 / DO NOT DO THIS ON LARGE LOGFILES!!!! This is the whole purpose of -11!x.
`a 10
`b 20

If successful the number of chunks executed is returned. If the end of the file is corrupt a 'badtail error is signalled. In the event that the log file references an undefined function, the function name is thrown as an error. This can be confusing if the missing function name is upd, as it does not reflect the same situation as the license expiry 'upd error. e.g.

/ Continuing the above example
q)delete f from `.
q)-11!`:logfile.2013.12.03 / function f no longer defined, so it throws an error

see the utilities in rescuelog.q for examples of usage.


same as −11!x


streaming execute the first n chunks of logfile x, return the number of chunks if successful.

It's possible to leverage the above to playback n records from record M onwards. e.g.

Firstly create a sample log file, which contains 1000 records as ((`f;0);(`f;1);(`f;2);..;(`f;999)).

q)`:log set();h:hopen`:log;i:0;do[1000;h enlist(`f;i);i+:1];hclose h;

then define function f to just print its arg, skip the first M records. If is defined, -11!x calls for each record.

q)m:0;M:750;f:0N!;{m+:1;if[m>M;value x;];};-11!(M+5-1;`:log)


given a valid logfile, return the number of chunks.

given an invalid logfile, return the number of valid chunks and length of the valid part.

q)logfile:`:good.log / a non-corrupted logfile
q)logfile:`:broken.log / a manually corrupted logfile
q)upd:{[x;y]} / define a dummy upd file as components are of the form (`upd;data)
q)hcount logfile
q)/ 26 valid chunks until position 35634 (out of 39623)




see/use .Q.addr


handle " escaping in strings (used to prepare data for csv export)


see/use md5


return the reference count for a variable

q)a:b:c:d:e:1 2 3


flip endian-ness of kdb+ data file x, see notes in Changes in kdb+ v2.6


returns compressed IPC byte representation of x, see notes about network compression in Changes in kdb+ v2.6


compress a file, see File Compression


see/use .Q.gc


compression statistics for file x, see File Compression


An optimized shortcut to obtain the length of uncompressed serialized x, i.e. count -8!x

q)v:til 100000
q)\t do[5000;-22!v]
q)\t do[5000;count -8!v]
q)(-22!v)=count -8!v


since kdb+ 3.1t 2013.03.04

Maps data into memory without copying.

q)-23!t:select from get`:t/; / previous tricks to force load included .. where i>=0


since kdb+ 3.3t 2014.10.07

read only evaluation, underpinning the keyword "reval", similar to eval (-6!), which behaves as if the cmd line option -b were active for the duration of the -24! call.

An example usage is inside the message handler, useful for access control, here blocking sync messages from updating -

q){reval(value;x)} / define on local process listening on port 500
q)h:hopen 5000 / from another process on localhost
'noupdate: `. `a


since kdb+ 3.4

Broadcast data as an async msg to specified handles. The advantage of using -25!(handles;msg) over neg[handles]@\:msg is that -25!msg will serialize msg just once - thereby reducing cpu and memory load.

Use as


handles should be a vector of int | longs > 0.

msg will be serialized just once, to the lowest capability of the list of handles. i.e. if handles are connected to a mix of versions of kdb+, it will serialize limited to the types supported by the lowest version. If there is an error, no messages will have been sent, and it will return the handle whose cap caused the error.

Just as with neg[handles]@\:msg, -25!x queues the msg as async on those handles - they don't get sent until the next spin of the main loop, or are flushed with neg[handles]@\:(::).

Possible error scenarios:

1)from trying to serialize data for a handle whose remote end does not support a type, or size of the data. e.g.

/ connect to 2.8 and 3.4
q)h:hopen each 5000 5001
5 6i 
q)(-5) 0Ng / 2.8 does not support guid
q)(-6) 0Ng / 3.4 does support guid 
'type error serializing for handle 5

2) in case an int is passed which is not a handle

q)-25!(7 8;0Ng)
'7 is not an ipc handle


kdb+ v3.4t 2016.05.12 View TLS settings on a handle or current process -26!handle or -26!()

see/use SSL


since kdb+ 3.3t 2015.02.17

underpins the json parser, .j.k.

For a complete list of functions, see the kdb+ Function Reference.

Personal tools