J 有哪些独特的功能?

发布于 2024-09-09 20:19:55 字数 132 浏览 2 评论 0原文

我有 C、Fortran、Python、R、Matlab 和一些 Lisp 背景,而且我读过一些关于 Haskell 的东西。 J 或 APL 家族的其他语言中有哪些独特的想法/示例,并且未在更常见的语言中实现?我总是很想知道我错过了什么......

I come from a background of C, Fortran, Python, R, Matlab, and some Lisp - and I've read a few things on Haskell. What are some neat ideas/examples in J or other languages from the APL family that are unique and not implemented in more common languages? I'm always interested in finding out what I'm missing...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

多情癖 2024-09-16 20:19:55

J 拥有大量的运算符,可以轻松创建复杂的程序,而无需寻找库。它具有极其强大的数组处理功能,以及迭代结构,使得显式控制结构与大多数用途无关——以至于我更喜欢​​使用张量代数来声明显式循环,因为它更方便。 J 在解释器中运行,但是一个好的 J 脚本可以与用编译器语言编写的程序一样快。 (当您取出显式循环时,解释器不必在每次执行时都编译循环的内容。)

J 的另一个有趣的功能是默认编程。您可以在不显式引用输入变量的情况下构建脚本,这使您可以纯粹根据您打算执行的操作来表达想法。例如,我可以将平均函数定义为“对列表中的项求和,然后除以列表中的条目数”,如下所示:

(+/ % #)

或者我可以制作一个切片成二维数组并仅返回平均值大于 10 的行的平均值的脚本:

(10&<#])(+/%#)"1

还有很多其他简洁的东西你可以使用 J;它是数学符号的一种可执行形式,思想很容易概括,因此你可以从学习该语言的工作原理的任何一个方面获得很多好处。

J has a very large set of operators that make it easy to gin up complex programs without having to hunt for a library. It has extremely powerful array processing capabilities, as well as iterative constructs that make explicit control structures irrelevant for most purposes -- so much so that I prefer using tensor algebra to declaring an explicit loop because it's more convenient. J runs in an interpreter, but a good J script can be just as fast as a program written in a compiler language. (When you take out explicit loops, the interpreter doesn't have to compile the contents of the loop every time it executes.)

Another fun feature of J is tacit programming. You can build scripts without explicit reference to input variables, which lets you express an idea purely in terms of what you intend to do. For example, I could define the average function as 'summing the terms in a list and dividing them by the number of entries in the list' like so:

(+/ % #)

or I could make a script that slices into a 2D array and only returns the averages of rows that have averages greater than 10:

(10&<#])(+/%#)"1

There's lots of other neat stuff you can do with J; it's an executable form of mathematical notation. Ideas generalize easily, so you get a lot of benefit out of learning any one aspect of how the language works.

小清晰的声音 2024-09-16 20:19:55

我认为 J 最有趣的方面之一是它是极少数甚至远程主流的非冯诺依曼语言之一。

嗯。 J主流?嗯,是的,与其他非冯诺依曼语言相比,确实如此!一开始只有极少数非冯诺依曼语言,其中大多数只存在于一些博士论文中并且从未实际实现,而那些已实现通常具有即使如此,用户群也为 1。一般来说,如果至少有一个用户不与发明者坐在同一层楼,那么它们就被认为是成功的。

那个相比,J主流。特别是,J 基于约翰·巴克斯 (John Backus) 的 FP,来自他的开创性图灵奖演讲“编程能否从冯·诺依曼风格中解放出来?”,并且据我所知,它是它唯一有效的实现。 (例如,我认为巴科斯从未真正实现过函数式编程。)

I think one of the most interesting aspects of J is that it is one of the very few non-von-Neumann languages that is even remotely mainstream.

Uhm. J mainstream? Well, yeah, compared to other non-von-Neumann languages it is! There are only very few non-von-Neumann languages to begin with, most of those only live inside some PhD thesis and were never actually implemented and those that were implemented usually have a userbase of 1 if even that. Generally, they are considered successful if at least one of the users doesn't sit on the same floor as the guy who invented it.

Compared to that, J is mainstream. In particular, J is based on John Backus's FP from his seminal Turing Award Lecture "Can Programming be Liberated from the von Neumann Style?" and it is AFAIK the only working implementation of it. (I don't think Backus ever actually implemented FP, for example.)

赢得她心 2024-09-16 20:19:55

这也许并不像我想象的那么独特,但我能想到的 J 的首要功能是隐式类型。它在执行和内存管理之上创建了一个很好的抽象级别,以专注于正在处理的数据。

假设您需要存储一个数字:

var1 =: 10

就这样完成了。大批?

var2 =: 4 8 15 16 23 42

完毕。哦,但是等等,你需要将其除以 3.7?不要为类型转换而烦恼,直接去做:

var2 % 3.7

摆脱类型转换、操作和分配的必要性是一个小小的祝福。

This is perhaps not as unique as I make it out to be, but the top feature I can think of for J is implicit typing. It creates that nice abstraction level above execution and memory management to focus on the data being processed.

Suppose you need to store a number:

var1 =: 10

And it's done. Array?

var2 =: 4 8 15 16 23 42

Done. Oh, but wait, you need to divide that by 3.7? Don't bother with casting, just go for it:

var2 % 3.7

Being rid of that necessity to cast and manipulate and allocate is a tiny blessing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文