Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
K (programming language)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Programming language}} {{More citations needed|date=August 2011}} {{Infobox programming language | name = K | logo = | paradigm = [[Array programming|array]], [[Functional programming|functional]] | year = {{Start date and age|1993 }} | designer = [[Arthur Whitney (computer scientist)|Arthur Whitney ]] | developer = Kx Systems | latest release version = | latest release date = <!-- {{Start date and age|2018}} --> | typing = [[Type system|dynamic]], [[Strong and weak typing|strong]] | website = {{URL|kx.com}} | implementations = | dialects = | influenced by = [[A+ (programming language)|A+]], [[APL (programming language)|APL]], [[Scheme (programming language)|Scheme]] | influenced = [[Q (programming language from Kx Systems)|Q]], [https://shakti.com/ Shakti] }} '''K''' is a proprietary [[Array data structure|array]] processing programming language developed by [[Arthur Whitney (computer scientist)|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.<ref>{{cite web|url=https://kx.com/| title=Kx Systems}}</ref> The language, originally developed in 1993, is a variant of [[APL (programming language)|APL]] and contains elements of [[Scheme (programming language)|Scheme]]. Advocates of the language emphasize its speed, facility in handling arrays, and expressive syntax.<ref>{{cite web|first=Kenneth|last=Iverson|title=Notation as a Tool of Thought|url=http://www.jsoftware.com/papers/tot.htm|access-date=2015-02-23|archive-url=https://web.archive.org/web/20130920071911/http://www.jsoftware.com/papers/tot.htm|archive-date=2013-09-20|url-status=dead}}</ref> == History == Before developing K, Arthur Whitney had worked extensively with APL, first at [[I. P. Sharp Associates]] alongside [[Kenneth E. Iverson|Ken Iverson]] and [[Roger Hui]], and later at [[Morgan Stanley]] developing financial applications. At Morgan Stanley, Whitney helped to develop [[A+ (programming language)|A+]], a variant of APL, to facilitate migrating APL applications from [[IBM]] [[mainframe computer]]s to a network of Sun [[workstation]]s. A+ had a smaller set of primitive functions and was designed for speed and to handle large sets of time series data.<ref>{{cite web|title=arthur bio and interview|url=http://queue.acm.org/detail.cfm?id=1531242}}</ref> In 1993, 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 K for UBS. The contract ended in 1997 when UBS merged with [[Swiss Bank Corporation|Swiss Bank]]. In 1998, Kx Systems released kdb+, a database built on K. kdb was an [[in-memory database|in-memory]], [[column-oriented DBMS|column-oriented]] database and included ksql, a query language with an [[SQL]]-like syntax. Since then, several 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 released in 2003 and kdb+/tick and kdb+/taq were released in 2004. kdb+ included [[Q (programming language from Kx Systems)|Q]], a language that merged the functions of the underlying K language and ksql.<ref>{{citation|last=Garland|first=Simon|url=http://vector.org.uk/weblog/archive/000036.html|title=Q Language Widening the Appeal of Vectors|publisher=Vector UK|date=December 28, 2004|url-status=dead|archive-url=https://web.archive.org/web/20070101213150/http://vector.org.uk/weblog/archive/000036.html|archive-date=January 1, 2007}}</ref> Whitney released a derivative of K called Shakti in 2018.<ref>{{Cite web|url=https://shakti.com/history/|title=Shakti}}</ref> == Overview == K shares key features with [[APL (programming language)|APL]]. They are both [[Interpreted language|interpreted]], [[Interactivity|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]] (as does another APL variant, [[J (programming language)|J]]). To allow for this, the set of primitive functions for K is smaller and heavily [[Function overloading|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 humans. For example, in the following contrived expression the [[exclamation point]] <code>!</code> refers to three distinct functions: <pre>2!!7!4</pre> Reading from right to left the first <code>!</code> is modulo division that is performed on 7 and 4 resulting in 3. The next <code>!</code> is enumeration and lists the integers less than 3, resulting in the list 0 1 2. The final <code>!</code> 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 object]]s, a concept borrowed from [[Scheme (programming language)|Scheme]]. [[First-class function]]s 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 bracket]]s. For example, in the following expression a quadratic expression is defined as a function and applied to the values 0 1 2 and 3: <syntaxhighlight lang="k">{(3*x^2)+(2*x)+1}'!4</syntaxhighlight> In K, named functions are simply function expressions stored to a variable in the same way any data value is stored to a variable. <syntaxhighlight lang="k">a:25 f:{(x^2)-1}</syntaxhighlight> 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 displayed immediately. Literal expressions such as strings evaluate to themselves. Consequently, the [["Hello, World!" program|Hello world]]-program is trivial: <pre> "Hello world!" </pre> The following expression sorts a list of strings by their lengths: <syntaxhighlight lang="k"> x@>#:'x </syntaxhighlight> 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. # @ uses 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: <syntaxhighlight lang="k"> {&/x!/:2_!x} </syntaxhighlight> 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 function below can be used to list all of the prime numbers between 1 and R with: <syntaxhighlight lang="k"> 2_&{&/x!/:2_!x}'!R </syntaxhighlight> 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. # 2_ drop the first two elements of the enumeration (0 and 1) ==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 functions of a [[relational database management system]]. The database supports [[SQL]], [[SQL-92]] and ksql, a query language with a syntax similar to SQL and designed for column based queries and array analysis. Kdb+ is available for several [[operating system]]s, including [[Solaris (operating system)|Solaris]], [[Linux]], [[macOS]], and [[Microsoft Windows|Windows]] (32-bit or 64-bit). ==See also== * [[J (programming language)|J]], another APL-inspired language * [[Q (programming language from Kx Systems)|Q]], the language of kdb+ and a new merged version of K and ksql. ==References== {{Reflist}} ==External links== * {{Official website|https://kx.com}}, Kx Systems * {{Official website|https://kx.com/solutions/}}, kdb+ * [http://www.math.bas.bg/bantchev/place/k.html Overview of K (with a link to K reference card)] * [https://web.archive.org/web/20230521013222/https://cs.nyu.edu/courses/fall07/G22.2965-001/kintro.html Dennis Shasha - K as a Prototyping Language] * [http://archive.vector.org.uk/art10010830 K by Arthur Whitney (2005)] * [https://johnearnest.github.io/ok/index.html oK] [[REPL]] for a K clone * [https://github.com/kevinlawler/kona/wiki ''Kona''] an open-source K3 implementation {{APL programming language}} [[Category:APL programming language family]] [[Category:Array programming languages]] [[Category:Data-centric programming languages]] [[Category:Dynamic programming languages]] [[Category:Function-level languages]] [[Category:Proprietary database management systems]] [[Category:Programming languages]] [[Category:Dynamically typed programming languages]] [[Category:High-level programming languages]] [[Category:1993 software]] [[Category:Programming languages created in 1993]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:APL programming language
(
edit
)
Template:Citation
(
edit
)
Template:Cite web
(
edit
)
Template:Infobox programming language
(
edit
)
Template:More citations needed
(
edit
)
Template:Official website
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)