读取J代码的最佳策略 [英] Best strategies for reading J code

查看:77
本文介绍了读取J代码的最佳策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用J几个月了,我发现阅读不熟悉的代码(例如,我没有写自己的代码)是该语言最具挑战性的方面之一,尤其是在默认情况下.过了一会儿,我想出了这个策略:

I've been using J for a few months now, and I find that reading unfamiliar code (e.g. that I didn't write myself) is one of the most challenging aspects of the language, particularly when it's in tacit. After a while, I came up with this strategy:

1)将代码段复制到Word文档中

1) Copy the code segment into a word document

2)从(1)中取出每个运算符,并将其放在单独的行上,以使其垂直读取

2) Take each operator from (1) and place it on a separate line, so that it reads vertically

3)用词汇"页面中的口头描述替换每个运算符

3) Replace each operator with its verbal description in the Vocabulary page

4)从J语法粗略翻译成英语语法

4) Do a rough translation from J syntax into English grammar

5)使用翻译来识别概念上相关的组件,并用换行符将其分开

5) Use the translation to identify conceptually related components and separate them with line breaks

6)用朴素的英语散文写出(5)中每个组成部分应该做什么的描述

6) Write a description of what each component from (5) is supposed to do, in plain English prose

7)根据(6)写出整个程序应该做什么的描述

7) Write a description of what the whole program is supposed to do, based on (6)

8)写出为什么可以说(1)中的代码代表(7)中设计概念的解释.

8) Write an explanation of why the code from (1) can be said to represent the design concept from (7).

尽管我从此过程中学到了很多东西,但我发现它相当艰巨且耗时-尤其是如果有人使用我以前从未遇到过的概念来设计程序.所以我想知道:J社区中的其他人是否有最喜欢的方法来找出模糊的代码?如果是这样,这些方法的优缺点是什么?

Although I learn a lot from this process, I find it to be rather arduous and time-consuming -- especially if someone designed their program using a concept I never encountered before. So I wonder: do other people in the J community have favorite ways to figure out obscure code? If so, what are the advantages and disadvantages of these methods?

我需要分解的一种代码示例如下:

An example of the sort of code I would need to break down is the following:

binconv =: +/@ ((|.@(2^i.@#@])) * ]) @ ((3&#.)^:_1)

我自己写了这个,所以我偶然知道它接受一个数字输入,将其重新解释为三进制数组,并将结果解释为以2为底的数字表示形式,最多重复一次. (例如,binconv 5 =(3 ^ 1)+ 2 *(3 ^ 0)-> 1 2->(2 ^ 1)+ 2 *(2 ^ 0)=4.)但是,如果我偶然发现了它而没有任何先前的历史记录或文档,弄清楚这是一件很重要的事情.

I wrote this one myself, so I happen to know that it takes a numerical input, reinterprets it as a ternary array and interprets the result as the representation of a number in base-2 with at most one duplication. (e.g., binconv 5 = (3^1)+2*(3^0) -> 1 2 -> (2^1)+2*(2^0) = 4.) But if I had stumbled upon it without any prior history or documentation, figuring out that this is what it does would be a nontrivial exercise.

推荐答案

尝试先将动词分解为各个组成部分,然后查看它们的作用.而且,您不必简单地引用vocab,您可以简单地尝试数据中的组件以查看其作用,并查看是否可以解决.要查看动词的结构,它有助于了解您正在查看的语音部分,以及如何识别基本结构(例如分叉)(当然,在较大的默认结构中也要用括号分隔).只需在ijx窗口中输入动词并按Enter即可破坏结构,并且可能会有所帮助.

Try breaking the verb up into its components first, and then see what they do. And rather than always referring to the vocab, you could simply try out a component on data to see what it does, and see if you can figure it out. To see the structure of the verb, it helps to know what parts of speech you're looking at, and how to identify basic constructions like forks (and of course, in larger tacit constructions, separate by parentheses). Simply typing the verb into the ijx window and pressing enter will break down the structure too, and probably help.

考虑以下简单示例:<.@-:@#{/:~

我知道<. -: # {/:都是动词,~是副词,而@是连词(请参阅词汇中的语音链接部分) ).因此,我可以看到这是一个具有左动词<.@-:@#,右动词/:~和dyad {的fork结构.这需要一些实践才能看到,但是有一种更简单的方法,让J通过在ijx窗口中键入结构并按Enter来向您显示该结构:

I know that <. -: # { and /: are all verbs, ~ is an adverb, and @ is a conjunction (see the parts of speech link in the vocab). Therefore I can see that this is a fork structure with left verb <.@-:@# , right verb /:~ , and dyad { . This takes some practice to see, but there is an easier way, let J show you the structure by typing it into the ijx window and pressing enter:

   <.@-:@#{/:~
+---------------+-+------+
|+---------+-+-+|{|+--+-+|
||+--+-+--+|@|#|| ||/:|~||
|||<.|@|-:|| | || |+--+-+|
||+--+-+--+| | || |      |
|+---------+-+-+| |      |
+---------------+-+------+

在这里您可以看到动词的结构(或者,在习惯于看这些动词之后,您将能够知道).然后,如果您无法识别作品,请与他们一起玩,看看它们的作用.

Here you can see the structure of the verb (or, you will be able to after you get used to looking at these). Then, if you can't identify the pieces, play with them to see what they do.

   10?20
15 10 18 7 17 12 19 16 4 2
   /:~ 10?20
1 4 6 7 8 10 11 15 17 19
   <.@-:@# 10?20
5

您可以进一步分解它们,并根据需要进行实验以弄清楚它们(这个小例子是中间动词).

You can break them down further and experiment as needed to figure them out (this little example is a median verb).

J将很多代码打包成几个字符,即使对于有经验的用户,大型的默认动词也看起来非常吓人.实验将比您的记录方法更快,并且通过尝试分解大型复杂动词,您可以真正了解到很多有关J的知识.我认为我建议您集中精力尝试查看语法结构,然后弄清楚各个部分,并逐步进行构建(因为这最终将使您编写默认的动词).

J packs a lot of code into a few characters and big tacit verbs can look very intimidating, even to experienced users. Experimenting will be quicker than your documenting method, and you can really learn a lot about J by trying to break down large complex verbs. I think I'd recommend focusing on trying to see the grammatical structure and then figure out the pieces, building it up step by step (since that's how you'll eventually be writing tacit verbs).

这篇关于读取J代码的最佳策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆