j

Is there a J idiom for adding to a list until a certain condition is met?

自闭症网瘾萝莉.ら 提交于 2019-12-10 13:49:33
问题 Imagine you're generating the Fibonacci numbers using the obvious, brute-force algorithm. If I know the number of Fibonaccis I want to generate in advance, I can do something like this using the power conjunction ^: : (, [: +/ _2&{.)^:20 i.2 How can I instead stop when the Fibonaccis reach some limit, say 1e6 ? (I know how to do this inside a function using while. , but that's no fun.) I want to stress that this is a general question about J, not a specific question about Fibonacci. Don't get

Best strategies for reading J code

梦想与她 提交于 2019-12-10 02:21:29
问题 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) Copy the code segment into a word document 2) Take each operator from (1) and place it on a separate line, so that it reads vertically 3) Replace each operator with its verbal description in the Vocabulary page 4) Do a rough translation from J

Applying an adverb to a list of gerunds

被刻印的时光 ゝ 提交于 2019-12-07 10:23:37
问题 Consider a list of gerunds and some data we wish to apply them to, cyclically: ms=.*`+`- NB. list of gerunds d =.3 4 5 6 NB. some data We can do: ms/ d NB. returns 9, ie, the result of 3 * 4 + 5 - 6 Now we pose the question: how does the result change if we change the order in which we apply the verbs? That is, we consider all 6 possible orders: allms=. (A.~i.@!@#) ms which looks like: ┌─┬─┬─┐ │*│+│-│ ├─┼─┼─┤ │*│-│+│ ├─┼─┼─┤ │+│*│-│ ├─┼─┼─┤ │+│-│*│ ├─┼─┼─┤ │-│*│+│ ├─┼─┼─┤ │-│+│*│ └─┴─┴─┘ To

Chain verbs in J

戏子无情 提交于 2019-12-07 03:29:08
问题 Suppose a boxed matrix containing various types: matrix =: ('abc';'defgh';23),:('foo';'bar';45) matrix +---+-----+--+ |abc|defgh|23| +---+-----+--+ |foo|bar |45| +---+-----+--+ And a column descriptor: columnTypes =: 'string';'string';'num' I want to apply verbs on this matrix by column according to types. I'll be using verbs DoString and DoNum: chain =: (('string';'num') i. columnTypes) { DoString`DoNum EDIT: The column descriptors are important, the decision on which verb to use is based on

Applying an adverb to a list of gerunds

若如初见. 提交于 2019-12-05 16:10:41
Consider a list of gerunds and some data we wish to apply them to, cyclically: ms=.*`+`- NB. list of gerunds d =.3 4 5 6 NB. some data We can do: ms/ d NB. returns 9, ie, the result of 3 * 4 + 5 - 6 Now we pose the question: how does the result change if we change the order in which we apply the verbs? That is, we consider all 6 possible orders: allms=. (A.~i.@!@#) ms which looks like: ┌─┬─┬─┐ │*│+│-│ ├─┼─┼─┤ │*│-│+│ ├─┼─┼─┤ │+│*│-│ ├─┼─┼─┤ │+│-│*│ ├─┼─┼─┤ │-│*│+│ ├─┼─┼─┤ │-│+│*│ └─┴─┴─┘ To answer the question, we can do: allms (4 : 'x/ y')"1 d NB. returns 9 _21 _1 _23 _41 _31 But notice I was

J: Why does `f^:proposition^:_ y` stand for a while loop?

孤人 提交于 2019-12-05 10:15:02
As title says, I don't understand why f^:proposition^:_ y is a while loop. I have actually used it a couple times, but I don't understand how it works. I get that ^: repeats functions, but I'm confused by its double use in that statement. I also can't understand why f^:proposition^:a: y works. This is the same as the previous one but returns the values from all the iterations, instead of only the last one as did the one above. a: is an empty box and I get that has a special meaning used with ^: but even after having looked into the dictionary I couldn't understand it. Thanks. f^:proposition^:_

Best strategies for reading J code

拜拜、爱过 提交于 2019-12-05 00:42:42
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) Copy the code segment into a word document 2) Take each operator from (1) and place it on a separate line, so that it reads vertically 3) Replace each operator with its verbal description in the Vocabulary page 4) Do a rough translation from J syntax into English grammar 5) Use the translation to identify conceptually related components and

APL versus A versus J versus K?

百般思念 提交于 2019-12-03 00:29:17
问题 The array-language landscape, while fascinating, is confusing to no end. Is there a reason to pick one of J or K or APL or A? None of these options seem to be open-sourced -- are there open sourced versions? I would love the expand my mind, but I remain befuddled. 回答1: The differences among these languages are relatively subtle. APL "proper" has the advantages, and disadvantages, of the original symbolic notation. (There are minor changes that have been made to the symbol set over the years,

APL versus A versus J versus K?

馋奶兔 提交于 2019-12-02 14:06:11
The array-language landscape, while fascinating, is confusing to no end. Is there a reason to pick one of J or K or APL or A? None of these options seem to be open-sourced -- are there open sourced versions? I would love the expand my mind, but I remain befuddled. kaleidic The differences among these languages are relatively subtle. APL "proper" has the advantages, and disadvantages, of the original symbolic notation. (There are minor changes that have been made to the symbol set over the years, but they're all true enough to the original vision.) The A+ language is available open source. It

How to list the code of a verb in J

我只是一个虾纸丫 提交于 2019-11-30 20:58:19
In the console, typing a single verb without parameters will print its content: tolower 3 : 0 x=. I. 26 > n=. ((65+i.26){a.) i. t=. ,y ($y) $ ((x{n) { (97+i.26){a.) x}t ) That's nice for development, but unexploitable during execution. Is there a way to do that dynamically? Is there a verb that can return the contents of another verb? For example: showverb 'tolower' or showverb tolower You can use its representation . For example the boxed representation ( 5!:2 ) of tolower is: (5!:2) <'tolower' ┌─┬─┬────────────────────────────────────────┐ │3│:│x=. I. 26 > n=. ((65+i.26){a.) i. t=. ,y│ │ │ │