J @没有按预期工作

时间:2009-07-01 16:55:07

标签: j tacit-programming

我刚开始尝试拿起J语言,并对以下内容感到困惑:

   1 2 +/@{ i.4
1 2
   +/ 1 2 { i.4
3

在@的文档中,它说:“x u @ v y↔u x v y”

我认为我只是误将一部分语言误认为另一部分,但无法弄明白

另外,我如何判断一个名字是什么类型的语音?

3 个答案:

答案 0 :(得分:4)

   NB. u b. 0 returns the rank of u
   NB. the rank of a verb determines the arguments it applies to at a time
   NB. monadic + y applies to atoms; dyadic x + y applies to pairs of atoms
   + b. 0
0 0 0
   NB. monadic +/ y and dyadic x +/ y apply to anything (unbounded rank)
   +/ b. 0
_ _ _
   NB. monadic { y applies to arrays of atoms;
   NB. dyadic x { y applies to pairs of atoms and anything
   { b. 0
1 0 _
   NB. u @ v has the rank of v
   +/@{ b. 0
1 0 _
   NB. since 1 2 { i.4 returns atoms at a time, +/ works on atoms
   +/"0 [ 1 2 { i.4
1 2
   NB. u @: v has unbounded rank
   +/@:{ b. 0
_ _ _
   NB. +/ applies to all of 1 2 { i.4 at once
   +/"_ [ 1 2 { i.4
3

   NB. mechanical translation to tacit form
   13 : '+/ x { y'
[: +/ {

答案 1 :(得分:1)

根据我的偏见,维基百科有一份关于等级的体面写作,以及它在J中“言语”不同部分的含义。

但是要回答最初的问题,J的跟踪工具可以用于理解其语法的工作原理:

   require'trace'
   trace '1 2 +/@{ i.4'

这将逐步引导您完成解析过程,显示每个生产规则所使用的单词以及每个生成规则生成的结果。

答案 2 :(得分:0)

啊,我想我可能已经弄明白了,我需要使用@:而不是@

   1 2 +/@:{ i.4
3

这就是我想要的。猜猜我将不得不在排名上阅读更多内容,这是@和@之间的唯一区别: