Appeared in:
Influenced by:
Typing discipline:
File extensions:
Programming language

K is a proprietary array programming language for database development and financial applications.

K was developed by Arthur Whitney after he left Morgan Stanley in 1993. Language commercialization was done by a newly created company Kx Systems which still exists nowadays. In 1998 they released a memory-based DBMS kdb written in K. A 64-bit version kdb+ was released in 2003; it included Q language which combined capabilities of K and ksql — an SQL-like query language. Nowadays the company offers only Q (both as part of kdb+ and apart of it), but in fact K (undocumented version K4) is available via Q interpreter. An alternate way to get K is to use an open-source implementation Kona.

K was created under strong influence of APL and Scheme, but it differs from both of them as well from other APL descendants. Language features:

  • Programs are written using ASCII charset, like in J. Primitive functions and operators are written using single non-alphanumeric characters; one character can have up to five meanings, the proper one is picked depending on the context.
  • The main data structures are heterogeneous lists consisting of elements of different data types. However, homogeneous lists (vectors) are actively used as well, and most K functions have versions suited for processing vectors.
  • Like J, K uses grammar terms to describe language entities, though it doesn’t take it so far. Data is referred to as nouns, data-processing functions are verbs, and higher-order functions are adverbs. The language has only 6 predefined adverbs, and doesn’t allow to create new user-defined ones.
  • Verbs can be atomic (applied to atomic values in the list regardless of how deep they are nested) and non-atomic (applied to a list in general). Most predefined verbs are monadic or dyadic, but generally a verb can have an arbitrary number of arguments.
  • Verbs are first-class objects, so they can be used in any context a noun can be.
  • The language also provides dictionaries — associative tables indexed with strings. They are used as building material for the K-tree.
  • K-tree is a method of data and code organization. The vertices of the tree are directories — global dictionary variables which contain data, code and other directories. At any given moment one of the directories is current, and all names are resolved with respect to it. This turns out to be a very efficient mechanism of implementing modularity and naming scopes.

Typically a K programmer interacts with the language via console; data input and visualization are done via GUI with widgets synchronized with corresponding variables.