我正在学习(并且让我大吃一惊)J,并阅读学习J。我注意到我学习的许多(所有?)动词的论点都非常灵活。我可以执行传统的 4 - 2
,或者我可以将它与列表一起使用,例如4 5 - 3 4
,甚至可以做 3 4 5 - 1
这似乎将运算符的右侧“提升”为数组,即使我只是给它一个标量。
我假设后一种行为包含在 ch.1 中的这一行中。上述文字2:
Consequently, the two arguments of = must have the same shapes, (or at least, as in the example of Y=2, compatible shapes). Otherwise an error results.
确实,3 4 5 - 2 3
是一个错误。 “兼容形状”的技术定义是什么?它是像“相同的形状或标量”一样简单,还是还有更多内容?
最佳答案
来自词典页面B. Verbs :
Agreement. In the phrase
p v q
, the arguments ofv
must agree in the sense that one frame must be a prefix of the other
所以以下内容都可以工作
(i. 2 3) * (i. 2 3 4) NB. frame of left arg is prefix of the right arg
(i. 2) * (i. 2 3 4) NB. frame of left arg is prefix of the right arg
(i. 2 3 4) * (i. 2 3) NB. frame of right arg is prefix of the left arg
有关框架的正式定义,请参阅词典页面 A. Nouns
我推荐this section of J for C programmers作为对这些概念的全面覆盖。
关于arrays - J 动词的数组参数 "compatible shape"是什么构成的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8814295/