# K（编程语言）

**K** 是一门交互式数组与列表处理语言，风格以函数式为主，由 Arthur Whitney（阿瑟·惠特尼）设计并实现，约于1993年首次发布，是 APL 简洁的、仅用 ASCII 字符的后裔。<sup>[1](https://www.math.bas.bg/softeng/bantchev/place/k.html)</sup> Kx Systems 正是在这门语言之上构建了 kdb+ 时间序列数据库和 q 编程语言，它也因此成为高频金融数据基础设施的基石之一。<sup>[2](https://www.geschichte-der-informatik.de/articles/apl_and_array_programming/)</sup>

| 关键事实 | 详情 |
|---|---|
| 设计者 | Arthur Whitney（阿瑟·惠特尼），独自一人设计并实现了 K<sup>[1](https://www.math.bas.bg/softeng/bantchev/place/k.html)</sup> |
| 首次发布 | 约1993年，同年惠特尼与 Janet Lustgarten（珍妮特·拉斯特加滕）共同创立 Kx Systems<sup>[1](https://www.math.bas.bg/softeng/bantchev/place/k.html)</sup><sup> • </sup><sup>[3](https://www.timestored.com/kdb-guides/history-of-kdb-arthur-whitney)</sup> |
| 源流 | APL 与 LISP 的综合：大部分能力来自 APL，但基本数据构造是列表，且语言基于 ASCII<sup>[4](https://github.com/kevinlawler/kona)</sup> |
| 体积 | 解释器与库小到可以装进处理器的缓存，程序以千字节计<sup>[2](https://www.geschichte-der-informatik.de/articles/apl_and_array_programming/)</sup> |
| 词汇量 | 约50个运算符，不带任何库；没有保留字，只用 ASCII 键盘字符<sup>[5](https://queue.org.cn/detail.cfm?id=1531242)</sup> |
| 后裔 | Kdb+（1998）、q（2003），以及 Shakti 的 k9；官方 K 实现由 KX Systems 作为 kdb+（K4）的一部分维护<sup>[3](https://www.timestored.com/kdb-guides/history-of-kdb-arthur-whitney)</sup><sup> • </sup><sup>[6](https://www.concatenative.org/wiki/view/K)</sup> |

## 源自 APL 传统

K 脱胎于 APL（A Programming Language），由 Kenneth Iverson（肯尼斯·艾弗森）发明——它最初是1950年代在哈佛大学的一种数学记号，到1964年成为一门语言。<sup>[7](https://code.kx.com/kdb-x/learn/q4m/0_Overview.html)</sup><sup> • </sup><sup>[3](https://www.timestored.com/kdb-guides/history-of-kdb-arthur-whitney)</sup> 1969年，惠特尼还是个孩子时就结识了艾弗森，后来在[华尔街](https://www.edgepedia.org/zh/wall-street)用 APL 工作，整个1970年代，这门语言在金融界都很有势力。<sup>[5](https://queue.org.cn/detail.cfm?id=1531242)</sup>

**先有 A+。** 1988年，[摩根士丹利](https://www.edgepedia.org/zh/morgan-stanley)邀请惠特尼提供咨询，将其庞大的 APL 基础设施从老旧的大型机迁移到分布式系统，他由此开发了 A+——一种带图形用户界面的 APL 方言，用于把 APL 应用从 IBM 大型机搬到 Sun 工作站上。<sup>[8](https://kparc.io/)</sup><sup> • </sup><sup>[9](https://computerhistory.org/profile/arthur-whitney/)</sup> 约1993年，他在同一方向上做了一次更彻底的重设计，K 由此诞生。<sup>[1](https://www.math.bas.bg/softeng/bantchev/place/k.html)</sup> 1993年，他离开摩根士丹利，与珍妮特·拉斯特加滕共同创立 Kx Systems；他们的第一份合同来自瑞银（UBS），瑞银由此获得 k1 的五年独家授权。<sup>[3](https://www.timestored.com/kdb-guides/history-of-kdb-arthur-whitney)</sup><sup> • </sup><sup>[4](https://github.com/kevinlawler/kona)</sup>

## 设计

K 保留了 APL 的数组取向，但改变了基本数据构造。在 APL 中，构造是多维的、类似矩阵的数组；在 K 中，则如 LISP 一样，是列表。<sup>[4](https://github.com/kevinlawler/kona)</sup> 惠特尼把这种词汇量描述为一种中间地带：早期 LISP 的原语太少，Common LISP 则有约2000个；他的语言约有50个操作，大小与 C 相当，而且完全不带库，所以用这些原语搭出来的程序非常短。<sup>[5](https://queue.org.cn/detail.cfm?id=1531242)</sup>

**ASCII 取代了 APL 的符号。** 惠特尼在摩根士丹利时用的是 APL 字符，但在1992年那一版 K 中他把它们去掉了，说这样做感觉很好，因为发电子邮件变得更容易了；这门语言没有保留字，只用 ASCII 键盘。<sup>[5](https://queue.org.cn/detail.cfm?id=1531242)</sup> 惠特尼估计自己常常越过那条简洁挤压可读性的界线，但他认为每行最多约七个操作尚可驾驭，因为人脑中能同时记住七样东西。<sup>[5](https://queue.org.cn/detail.cfm?id=1531242)</sup>

设计目标是速度。惠特尼自述的动机是做一门快速的通用解释型语言；小巧的解释器和库被控制在处理器缓存的容量之内，其在时间序列数据上的性能，在许多工作负载下是其他语言比不上的。<sup>[10](https://www.hpcwire.com/bigdatawire/2020/10/29/kx-systems-a-historical-need-for-speed/)</sup><sup> • </sup><sup>[2](https://www.geschichte-der-informatik.de/articles/apl_and_array_programming/)</sup>

## 版本与通往 q 之路

Kx 的各个版本很容易混淆，因为这些名称常被混用。在 k2 之前，瑞银持有 k1 的独家授权；k2 是 Kx 的主力产品；k3 随后；k4 则是当前产品的底层。<sup>[4](https://github.com/kevinlawler/kona)</sup> 周边产品的时间线如下：<sup>[3](https://www.timestored.com/kdb-guides/history-of-kdb-arthur-whitney)</sup>

- **1988**：A+，惠特尼在摩根士丹利开发。
- **1993**：K，APL 的简洁变体。
- **1998**：Kdb+，内存中的列式数据库。
- **2003**：q，包在 k 外面、提供可读性的一层封装。

更早的数据库语言 Ksql 是用 K 实现的；把它与语言本身合并，既提高了生产力，又缩小了程序体积。<sup>[1](https://www.math.bas.bg/softeng/bantchev/place/k.html)</sup> 在 q 中，类 APL 语言特有的运算符兼性（同一运算符可用于一个或两个参数）被规避了：所有单目运算符都改用单词命名，于是 `+`、`@`、`#`、`$` 这类符号只表示双目用法；兼性在 K4 中仍然保留。<sup>[1](https://www.math.bas.bg/softeng/bantchev/place/k.html)</sup>

**q 的底下是 K。** Kx 作为编程语言提供的只有 q，而非 K，但 q 的实现就是 K4：它的语法以及表和查询处理都是用 K4 写的库，解释器可以在 q 与 K 模式之间切换以运行 K 脚本，不过 K4 没有官方文档。<sup>[1](https://www.math.bas.bg/softeng/bantchev/place/k.html)</sup> KX 把 q 描述为一门用 k（有时称为 k4）实现的嵌入式领域特定语言。<sup>[11](https://code.kx.com/q//basics/parsetrees/)</sup> 惠特尼本人则继续作为源代码的唯一开发者。<sup>[12](https://podscripts.co/podcasts/algorithms-data-structures-programs/episode-96-the-k-programming-language)</sup>

## Kdb+ 与金融应用

K 的主要商业应用是 kdb+，一个基于列、具备流处理能力的混合式内存数据库，面向大容量、高速度时间序列数据（如价格、成交量和头寸）的分析型工作负载。<sup>[13](https://www.odbms.org/wp-content/uploads/2015/01/1408-Kdb-_and_the_Internet_of_Things_Big_Data.pdf)</sup><sup> • </sup><sup>[14](https://www.cmegroup.com/content/dam/cmegroup/education/files/big-data-investment-management-the-potential-to-quantify-traditionally-qualitative-factors.pdf)</sup> 自2001年起，它被用于投资管理的前台部门，用于历史数据驱动实时分析的黑箱交易，其应用语言与流处理紧密耦合。<sup>[14](https://www.cmegroup.com/content/dam/cmegroup/education/files/big-data-investment-management-the-potential-to-quantify-traditionally-qualitative-factors.pdf)</sup> kdb+ 的 tick 架构于2000年代初发布，是一套生产级流数据系统，用于实时捕获、存储和查询高频时间序列数据，二十多年来已部署在许多顶尖投资银行和金融机构。<sup>[15](https://code.kx.com/kdb-x/learn/brief-introduction.html)</sup>

独立基准测试支持了它的性能声誉。2023年一项 arXiv 研究以加密货币交易所数据模拟金融高频工作负载，对 [ClickHouse](https://www.edgepedia.org/zh/clickhouse)、InfluxDB、kdb+ 和 TimescaleDB 进行了基准测试，发现 kdb+ 在受测数据库中性能最高。<sup>[16](https://arxiv.org/abs/2301.12561)</sup>

## 实现与社区

官方实现是专有的，由 KX Systems 作为 kdb+（K4）的一部分维护。<sup>[6](https://www.concatenative.org/wiki/view/K)</sup> Kx 之外存在开源实现。惠特尼本人后来的工作也继续在 Kx 之外进行：Shakti（k9）作为 kdb+/q 的继任者正在积极开发中。<sup>[17](https://codearchaeology.dev/languages/k/)</sup>

K 的影响还贯穿于更广的数组语言家族。惠特尼昔日的同学 Roger Hui（罗杰·许）曾提到，一个早期 K 解释器的组织方式与编程风格，启发了开发 J 的团队——J 正是艾弗森对 APL 的 ASCII 化重新构想。<sup>[8](https://kparc.io/)</sup><sup> • </sup><sup>[2](https://www.geschichte-der-informatik.de/articles/apl_and_array_programming/)</sup>

## References

1. [K, Nikolay Bantchev, Institute of Mathematics and Informatics, Bulgarian Academy of Sciences](https://www.math.bas.bg/softeng/bantchev/place/k.html)
2. [APL: The Language Written in Its Own Alphabet, Geschichte der Informatik](https://www.geschichte-der-informatik.de/articles/apl_and_array_programming/)
3. [History of Kdb+/q Database, TimeStored](https://www.timestored.com/kdb-guides/history-of-kdb-arthur-whitney)
4. [Kona: Open-source implementation of the K programming language, GitHub](https://github.com/kevinlawler/kona)
5. [A Conversation with Arthur Whitney, ACM Queue (2009), Chinese mirror](https://queue.org.cn/detail.cfm?id=1531242)
6. [K, Concatenative wiki](https://www.concatenative.org/wiki/view/K)
7. [Overview, Q for Mortals, KDB-X Documentation](https://code.kx.com/kdb-x/learn/q4m/0_Overview.html)
8. [kparc.io: The origins of k](https://kparc.io/)
9. [Arthur Whitney, Computer History Museum](https://computerhistory.org/profile/arthur-whitney/)
10. [Kx Systems: A Historical Need for Speed, BigDATAwire (2020)](https://www.hpcwire.com/bigdatawire/2020/10/29/kx-systems-a-historical-need-for-speed/)
11. [Parse trees, kdb+ and q documentation](https://code.kx.com/q//basics/parsetrees/)
12. [Episode 96: The K Programming Language, Algorithms + Data Structures = Programs transcript](https://podscripts.co/podcasts/algorithms-data-structures-programs/episode-96-the-k-programming-language)
13. [Kdb+ and the Internet of Things/Big Data, ODBMS.org](https://www.odbms.org/wp-content/uploads/2015/01/1408-Kdb-_and_the_Internet_of_Things_Big_Data.pdf)
14. [Big Data & Investment Management, CME Group](https://www.cmegroup.com/content/dam/cmegroup/education/files/big-data-investment-management-the-potential-to-quantify-traditionally-qualitative-factors.pdf)
15. [A brief introduction to q and KDB-X, KDB-X Documentation](https://code.kx.com/kdb-x/learn/brief-introduction.html)
16. [Benchmarking Specialized Databases for High-frequency Data, arXiv:2301.12561](https://arxiv.org/abs/2301.12561)
17. [K, CodeArchaeology](https://codearchaeology.dev/languages/k/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Programming languages › Individual programming languages › Functional, logic, and array languages

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/k-programming-language

English original: https://www.edgepedia.org/k-programming-language
