K (programming language)

K (programming language)

Infobox programming language
name = K
logo =
paradigm = array, functional
year = 1993
designer = Arthur Whitney
developer = Kx Systems
latest release version =
latest release date =
typing = dynamic, strong
implementations =
dialects =
influenced_by = A+, APL, Scheme
influenced =

K is a proprietary array processing language developed by Arthur Whitney and commercialized by Kx Systems. The language serves as the foundation for KDB, an in-memory, column-based database, and other related financial products. The language, originally developed in 1993, is a variant of APL and contains elements of Scheme. Advocates of the language emphasize its speed, facility in handling arrays and its expressive syntax.

History

Before developing K, Arthur Whitney had worked extensively with APL, first at I. P. Sharp Associates alongside Ken Iverson and Roger Hui, and later at Morgan Stanley developing financial applications. At Morgan Stanley, Whitney developed A+, a variant of APL, to facilitate the migration of APL applications from IBM mainframes to a network of Sun workstations. A+ had a smaller set of primitive functions and was designed for speed and to handle large sets of time series data.

In 1993, Arthur Whitney left Morgan Stanley and developed the first version of the K language. At the same time he formed Kx Systems to commercialize the product and signed an exclusive contract with Union Bank of Switzerland (UBS). For the next four years he developed various financial and trading applications using the K language for UBS.

The contract ended in 1997 when UBS merged with Swiss Bank. In 1998 Kx Systems came out with KDB, a database built on K. KDB was an in-memory , column-oriented database and included Ksql, a query language with a SQL like syntax. Since then a number of financial products have been developed with K and KDB. KDB/tick and KDB/taq were developed in 2001. KDB+, a 64-bit version of KDB was brought out in 2003 and KDB+/tick and KDB+/taq were brought out the following year. KDB+ included Q, a language that merged the functionality of the underlying K language and Ksql. [citation|url=http://vector.org.uk/weblog/archive/000036.html|title=Q Language Widening the Appeal of Vectors|publisher=Vector UK]

Overview

K shares key features with APL. They are both interpreted, interactive languages noted for concise and expressive syntax. They have simple rules of precedence based on right to left evaluation. The languages contain a rich set of primitive functions designed for processing arrays. These primitive functions include mathematical operations that work on arrays as whole data objects, and array operations, such as sorting or reversing the order of an array. In addition, the language contains special operators that combine with primitive functions to perform types of iteration and recursion. As a result, complex and extended transformations of a dataset can be expressed as a chain of sub-expressions, with each link performing a segment of the calculation and passing the results to the next link in the chain.

Like APL, the primitive functions and operators are represented by single or double characters; however, unlike APL, K restricts itself to the ASCII character set (a feature it shares with J, another variant of APL). To allow for this, the set of primitive functions for K is smaller and heavily overloaded, with each of the ASCII symbols representing two or more distinct functions or operations. In a given expression, the actual function referenced is determined by the context. As a result K expressions can be opaque and difficult to parse. For example, in the following contrived expression the exclamation point “!” refers to three distinct functions:

2!!7!4
Reading from right to left the first ! is modulo division that is performed on 7 and 4 resulting in 3. The next ! is enumeration and lists the integers less than 3, resulting in the list 0 1 2. The final ! is rotation where the list on the right is rotated two times to the left producing the final result of 2 0 1.

The second core distinction of K is that functions are first-class objects, a concept borrowed from Scheme. First-class functions can be used in the same contexts where a data value can be used. Functions can be specified as anonymous expressions and used directly with other expressions. Function expressions are specified in K using curly brackets. For example, in the following expression a quadratic expression is defined as a function and applied to the values 0 1 2 and 3:

{(3*x^2)+(2*x)+1}'!4
In K, named functions are simply function expressions stored to a variable in the same way any data value is stored to a variable.
x:25f:{(x^2)-1}

In addition functions can be passed as an argument to another function or returned as a result from a function.

Examples

K is an interpreted language where every statement is evaluated and its results immediately displayed. Literal expressions such as strings evaluate to themselves. Consequently, the Hello world-program is trivial:

"Hello world!"
The following expression sorts a list of strings by their lengths:
x@>#:'x
The expression is evaluated from right to left as follows:
# #:'x returns the length of each word in the list x.
# > returns the indices that would sort a list of values in descending order.
# @ use the integer values on the right to index into the original list of strings.

A function to determine if a number is prime can be written as:

{&/x!/:2_!x}
The function is evaluated from right to left:
# !x enumerate the positive integers less than x.
# 2_ drops the first two elements of the enumeration (0 and 1).
# x!/: performs modulo division between the original integer and each value in the truncated list.
# &/ find the minimum value of the list of modulo result.If x is not prime then one of the values returned by the modulo operation will be 0 and consequently the minimal value of the list. If x is prime then the minimal value will be 1, because x mod 2 is 1 for any prime greater than 2.

The above function can be used to list all of the prime numbers between 1 and R with:

(!R)@&{&/x!/:2_!x}'!R
The expression is evaluated from right to left
# !R enumerate the integers less than R.
# ' apply each value of the enumeration to the prime number function on the left. This will return a list of 0's and 1's.
# & return the indices of the list where the value is 1.
# @ use the integer values listed on the right to index into the list on the left.
# (!R) A list of integers less than R.

Performance characteristics

The performance of modern CPUs is improving at a much faster rate than their memory subsystems. 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. Vector processing makes efficient use of the cache row fetching mechanism and posted writes without introducing bubbles into the pipeline by creating a dependency between consecutive instructions.

GUI

The GUI library included in K is based on that of A+, but it takes advantage of many features unique to K. K's GUI is declarative and data-driven, as opposed to most GUIs which are imperative. A window and the things in a window are contained in a normal data structure, usually a dictionary on the K Tree, and displayed with the $ operator. Information about a widget is kept in the variable's attributes. Every data type in K can function as a widget - just not necessarily very well.

But in K, the GUI library is so terse and easy to useFact|date=November 2007 that even for prototyping, developers often use a GUI interface rather than a command line. A minimal, not very pretty GUI Hello world in K is `show$"Hello world"

The latest version of the K programming language, known as "K4", no longer has a built-in GUI library.

K financial products

K is the foundation for a family of financial products. Kdb is an in-memory, column-based database with much of the same functionality of a relational database management system. The database supports SQL, (sql92) and ksql, a query language with a syntax similar to SQL and designed for column based queries and array analysis.

kdb is available for Solaris, Linux, and Windows (32-bit or 64-bit).

ee also

* APL, the first array language
* J, another APL-inspired language
* Q, The language of KDB+ and a new merged version of K and KSQL.

References

* [http://www.kx.com kxsystems]
* [http://code.kx.com code.kx.com username:anonymous, password:anonymous]
* [http://www.firstderivatives.com First Derivatives]
* [http://www.skelton.de Skelton Consulting GmbH]
* Q For Mortals: A Tutorial in Q Programming, by Jeffry A Borror, AISBN 78-1434829016.

External links

* [http://www.kx.com/index.php Kx Systems]
* [http://www.kx.com/products/database.php Official page for KDB+]
* [http://www.kx.com/news/in-the-news/sql-timeseries.php SQL and the Problem with Time Series]
* [http://www.cs.nyu.edu/courses/fall02/G22.3033-007/kintro.html Dennis Shasha - K as a Prototyping Language]
* [http://www.kuro5hin.org/?op=displaystory;sid=2002/11/14/22741/791 A Shallow Introduction to the K programming language] Article from Kuro5hin
* [http://www.nsl.com No Stinking Loops - lot of stuff about K]
* [http://vrabi.web.elte.hu/k/ K examples]
* [http://www.cs.nyu.edu/~michaels/screencasts/Java_vs_K/Java_vs_K.html Michael Schidlowsky - Screencast comparing solutions of a specific problem] in K vs. Java


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Programming language — lists Alphabetical Categorical Chronological Generational A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that… …   Wikipedia

  • Programming language theory — (commonly known as PLT) is a branch of computer science that deals with the design, implementation, analysis, characterization, and classification of programming languages and programming language features. It is a multi disciplinary field, both… …   Wikipedia

  • Programming Language Design and Implementation — (PLDI) is one of the ACM SIGPLAN s most important conferences. The precursor of PLDI was the Symposium on Compiler Optimization, held July 27–28, 1970 at the University of Illinois at Urbana Champaign and chaired by Robert S. Northcote. That… …   Wikipedia

  • Programming Language for Business — or PL/B is a business oriented programming language originally called DATABUS and designed by Datapoint in the early 1970s as an alternative to COBOL because its 8 bit computers could not fit COBOL into their limited memory, and because COBOL did …   Wikipedia

  • programming language — ➔ language * * * programming language UK US noun [C] ► COMPUTER LANGUAGE(Cf. ↑computer language) …   Financial and business terms

  • programming language — Language Lan guage, n. [OE. langage, F. langage, fr. L. lingua the tongue, hence speech, language; akin to E. tongue. See {Tongue}, cf. {Lingual}.] [1913 Webster] 1. Any means of conveying or communicating ideas; specifically, human speech; the… …   The Collaborative International Dictionary of English

  • Programming Language One — Programming Language One, oft als PL/I (auch PL/1, PL1 oder PLI) abgekürzt ist eine Programmiersprache, die in den 1960er Jahren von IBM entwickelt wurde. Die Bezeichnung PL/1 ist vor allem in Deutschland gebräuchlich. Ursprünglich wurde PL/I… …   Deutsch Wikipedia

  • Programming Language 1 — noun A computer programming language which combines the best qualities of commercial and scientific oriented languages (abbrev PL/1) • • • Main Entry: ↑programme …   Useful english dictionary

  • Programming Language —   [engl.], Programmiersprache …   Universal-Lexikon

  • Programming language specification — A programming language specification is an artifact that defines a programming language so that users and implementors can agree on what programs in that language mean.A programming language specification can take several forms, including the… …   Wikipedia

  • programming language — noun (computer science) a language designed for programming computers • Syn: ↑programing language • Topics: ↑computer science, ↑computing • Hypernyms: ↑artificial language …   Useful english dictionary

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”