看到一篇反映了一些多数人对 APL 的误解的 art,决定写点文章让更多人了解真正的 APL。
在原始APL里,求平均数,通常的写法是
$avg\leftarrow \{(+\omega)\div\not\equiv \omega\}$
我不知道原始的 APL 指的是啥,不过 direct definition (用 {} 定义匿名函数, $\alpha\ \omega$ 指代参数) 是 Dyalog 搞的,叫 D-function,后來改叫 dfns,然後其它如 GNU APL 仿了 Dyalog 的这个feature,而且这个实现的历史可沒那么早
可以查到的是
These ideas were first presented in the Dyadic Vendor Forum at APL96 where they appeared to meet with general approval. Dfns were introduced with APL/W version 8.1 release 1 in early 1997.3
direct definition 设计的來源可以查到 Ken Iverson 的 Turing Award lecture Notation as a Tool of Thought。不过那时只有个很粗浅的 direct definition to header form 的 subroutine,并不能直接用 arrow 赋值,更沒有能让 dfsn 被称为 FP lang 的 lexical scope,guard。
The first line of code in the J implementation was
written on Sunday, August 27, 19894
但是保守一点,最晚 1991 年吧,这个时候 Ken Iverson 用 J 写的 Arithmetic5里己有用文章提到的 [ ] op 了。而且同书中 J 也有和 direct definition 相似但出奇鬼畜的 Explicit Definition。
所以硬要用个更新的 feature 当成 legacy 和一个语言中不能起到 eliminate 更难用的同类功能作用的 feature 比较,这样的讲理说服力堪优啊。
J使用了 [ 和 ] 这两个函数
x [ y = x
x ] y = y
这不就是 APL 的 $\dashv\ \vdash$ 么。
Roger and I then began a collaboration on the design and implementation of a dialect of APL(later named J by Roger), first deciding to roughly follow “A Dictionary of APL”6
于是就䃼正个了这样几个微妙的误解。
ps. Dyalog 有个 dfns to tacit 的 tut ,不过只对 Dyalog 适用。GNU APL 用不來。
另外下一篇更正式的关于 APL 的介绍也在写呢
APL 是四门语言,一是 A Programming Language 书设计的 elements of programming。
二为 IBM Selectric 上的正交性非常的 symbol notation。
三为据传來自 Elementary Analysis (这书太老找不到) 的 direct definition form,Dyalog 叫 dfns 的 FP language。
四为 Ken Iverson 后來重新发明的 J。
FAQ:
Q: J 比 APL 先进吗?
A: J 比 J 之前的 APL 先进。J 之后的包括 Dyalog 在內吸收了不少 J 的特性呢。
Q: J 和 APL 什么关系?
A: 两个都是加拿大数学家 K. E. Iverson 参与设计的。比較有意思的是 JSoftware 是 Ken Iversion 他儿子 Eric Iversion 的公司,也就是老子给儿子打工。
Q: 我能用 APL 找到工作吗?
A: 我听说过有个在 STSC 搞 APL 的离职以后被大学資助读了个数学 phd 教书的说。