编程与软件工程t3x.org
Klong:一种简单的数组语言
Klong: A Simple Array Language
2015 — 2025,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
Klong 是一门极简的数组语言(APL/J/K 家族),由作者独立实现,包含基于类 Forth 虚拟机的解释器,并配有免费书籍《Klong Book》。它刻意精简了 J/K 中的歧义,使数组编程风格更易上手。
为什么经久不衰:它把数组语言的核心思想压缩到极小、可完全装进脑子的语言里,多次跨越十年登上 HN,是学习 APL/J/K 思维的低门槛入口。
HN 评论精选
Klong 比 J/K 更易学,是进入数组语言世界的良好跳板
我读了《Klong 书》后,它以一种 J/K 从未做到的方式让我“开窍”了。作者把语言精简得很到位,清理了许多歧义,使其平易近人。读完之后我反而觉得 APL 和 J 也更容易接近了。我还用 Klong 实现了 k-means 聚类,它构建在类 Forth 的虚拟机之上、使用作者自己写的 Scheme 内核,性能不算快但足够用。我就是喜欢 Klong——它很有趣。
nprescott查看英文原文
I read the Klong book [0] and for me it "clicked" in a way that J/K never had. The author did a really nice job paring down the language and cleaning up some of the ambiguities in a way that made it approachable. Also, after reading it I've found APL and J more approachable, which is encouraging. If you'll forgive the style, I took a swing at implementing k-means clustering in Klong a few months ago [1]. While I did find a few slow-downs with a modestly sized data set (Fisher's iris data), I think Klong is built on a Forth-like VM using the core of a scheme implementation (all of which the author wrote!). It wasn't slow enough to really bother me, as I was more interested in learning about array languages and algorithms. I'm a fan of Klong -- it's just fun. [0]: http://www.t3x.org/klong/book.html [1]: https://idle.nprescott.com/2019/k-means-clustering-in-klong.html
小而完整的数组语言(Q/K)证明无需层层抽象和庞大技术栈也能强大
我用基于 K 的 Q 语言做 Advent of Code。它让我重新思考语言和编程应该是什么样子。在 Q 中抽象完全没必要,库也没必要——整个语言能装进脑子,所有代码都由基本构件组成。它不像 Scheme 那样鼓励层层抽象,而是让“代码复用”这个假先知变得多余。金融界的朋友用它做高频交易和历史 tick 数据研究,整个技术栈就是一个能完全装进 CPU 缓存的小可执行文件,同时充当运行时和数据库——没有 Kafka、Redis、Kubernetes,没有 DevOps 折腾。
smabie查看英文原文
I’ve been using Q (built on K) for Advent of Code. It’s an amazing language that has made me reconsider what a language and programming should be. I come from a FP background and have always considered abstraction the heart of powerful and expressive programming. In Q, abstraction is wholly unnecessary. Libraries are unnecessary. I can fit the entire language in my head and all code in the language is built out of the fundamental building blocks of it. There’s no layer after layer of abstraction, just a small base of operators and functions. One might be tempted to compare it to other small languages, like Scheme. But for Scheme it’s intended that you build higher and higher levels of abstractions. With Q it’s both small and compact, and one rarely if ever feels the need to actually build a library of utility functions or anything really: it renders unnecessary the false prophet of code reuse. I got interested in Q because some of my friends at other financial institutions were using it for HFT and research on historical tick data. I found it surprising at the time I that their software stacks could be so simple, essentially just a single small executable that entirely fit in the CPU cache that managed both the runtime and their entire database. At the time I thought this was impossible, but now I realize how possible and eminently reasonable this was. Instead of Kafka and Redis and SQL Dbs and Kubernetes and god knows what else, you just have Q. No DevOps bullshit, no containers, no complex shit to manage. In the past 3 weeks I’ve had to rethink my philosophy of what software needs to be and have concluded that most of us are doing things very very wrong: we’ve created this unnecessary world of complexity that is tantamount to masturbation. Now let’s talk about the language itself. It may look complex, but it’s actually quite simple. The only real data types are lists, dictionaries, symbols, and numbers. And surprisingly, that’s enough. When programming in it I have no desire for classes or objects or trees or whatever, in fact, just using lists and dictionaries can usually solve the problem in a better way. Also, while Q is interpreted, it’s so goddamn fast. I’ve done some benchmarks against C and Q is about as fast, sometimes even faster. The optimizations the interpreter does are just insane. Not even joking, a single line of Q can accomplish somewhere between 100 to 1000 lines of what the equivalent C code would look like. Another plus is that editor tooling is unnecessary, I have no need for autocomplete or inline docs because I can literally remember the entire thing. And since Q is so compact, I can view an entire program on a single screen, no scrolling, no jumping between files. I’ve also noticed that I can remember the verbatim definition of my code. I can almost perfectly remember my exact code for each Advent of Code solution. Anyways, good luck on Klong, I’m going to check it out. I don’t like J and wish there was a good open source K/Q like language. I don’t actually like K because the overloads on function arity creates a lot of complexity (Q does away with this), so Klong might be right up my alley! For anyone who hasn’t tried an array based language, I highly recommend it. Q has expanded my mind more than I thought possible at this point in my career. My last really mind expanded experience in programming was when I picked up Scheme and Haskell in high school. And now after using Q, those languages aren’t that great anyways!
质疑其“简单”的说法:单字符运算符和非常规优先级对初学者并不友好
以素数检查为例:{&/x!:\2+!_x^1%2} 相当于 C 风格的 min((2..sqrt(x)).map(y -> x % y)) == 1。Klong 真的“简单”吗?是实现和解析更容易,还是语法一旦习惯就更简单?大量单字符运算符 & ! : _ 带着不常见的含义和优先级规则,我觉得很反直觉。
chvid查看英文原文
From https://t3x.org/klong/prime.html: {&/x!:\2+!_x^1%2} This is function that checks if the value given as first parameter x is a prime by running through the numbers 2 to square root of x and applying the function x modulus y, then it looks at the minimum of the resulting list and see if it is 1 or 0. If it is one then x is a prime. Written in a language with c-style syntax it would be something like: x -> min((2 .. sqrt(x)).map(y -> x % y)) == 1 Why is Klong simple? Is it easier to implement, parse and interpretate? Or is the syntax somehow simpler once you get used to it? The former maybe; but it doesn't seem to be a part of the language's pitch. The latter is surely in the eyes of the beholder. I find it counter-intuitive to have so many single character operators & ! : _ with uncommon meaning and precedence rules.
从右到左的求值顺序是数组语言入门的障碍
从右到左的求值顺序是所有数组语言的共性吗?这确实不利于新人入门。
renox查看英文原文
Is the right to left order common to all array language? It sure doesn't help onboarding..
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选