k is a vector-based (or array-oriented) programming language in the vein of APL, created by Arthur Whitney based on his previous work (including another APL derivative called A+, developed during his time at Morgan Stanley).

Like its contemporary language J (by APL's creator, Ken Iverson), k restricts itself to the ASCII character set for interoperability (unlike APL, which had a character set tailored to its usage pattern). Because of this, the ``normal'' ASCII punctuation characters are nearly all reserved for some use (much as in J).

However, J and k are following significantly different paths, both from a technical standpoint and a marketing/purpose standpoint. Where J focuses primarily on an academic/pedagogical audience and caters to this with copious documentation and its interesting tacit definitions, k is the basis for a commercial venture rooted at http://kx.com; kdb, built on top of k, claims to be a high-performance relational database system (on the order of Oracle and Sybase) with features making it especially convenient for financial applications.

From a programming language standpoint, k's interesting deviations from J include ragged (that is, non-rectangular) arrays, zero-based indexing, and user-defined functions with any number of arguments (as opposed to a mandated 1 or 2).

Those differences aside, k shares many of J's traits (as well as those of all APL derivatives):

  • Many important operations are already built into the language, like < and > (grade up and grade down for sorting), ? (list lookup), and = (group, equivalent to J's self-classify).
  • Most builtins operate on vectors as well as they do scalars (if not better); x+y can be the sum of scalars, vectors, matrices, conformable ragged arrays, or even a single scalar increment to any of the above (if one operand is a scalar).
  • For all of these reasons, good k programs have a very high ``meaning to length'' ratio, so a k program to accomplish a given task will often be much shorter than an equivalent (for example) C or Java program.
As an interesting consequence of k's right-to-left evaluation order, idiomatic k reads very nicely from left to right (from http://kx.com/a/k/examples/tab.k):
  • cut:{1_'(&x=*x)_ x:"\t",x}: ``cut is one drop each where x equals first x cut x is tab join x''...prepend a tab to x, then cut x into pieces everywhere where it has a tab (first x), then drop the first element of each chunk (the tab).
  • join:{1_,/"\t",'x}: ``join is one drop join over tab join each x''...prepend a tab to each chunk of x, join them together (accumlating over all chunks), then drop the first element (the extra tab separator).

For more details and examples, see the E2 k programming reference.

From Arthur's http://kx.com/a/k/readme.txt:


k is a high-level general-purpose programming language.
it is used for high performance database and analysis.
syntax is simple infix/prefix: x**y is x times first y
k programs are short.

 "hello world"
 +/x                            / plus OVER x (i.e. sum x)
 1_'(&x=y)_ y:x,y               / 1 drop EACH(where x=y)cut y:x join y
 @[close;stock;;price]'(|;&;:)  / amend close at stock with (high;low;close)