4 ms·
FB"0 basically means apply FB to each cell in an array. i.100 makes an array of numbers 0...99 and >: increments every number in that array by 1 So it's mappin
by Avshalom 10y ago
FB"0 basically means apply FB to each cell in an array.
i.100 makes an array of numbers 0...99 and >: increments every number in that array by 1
So it's mapping FB over the numbers 1 to 100.
Now I don't know j very well so I don't know why this evaluates as (FB"0) (>:i.100) instead of (FB") (0>:i.100) but I guess " is special
1337 is just a stand in number. To try the algorithm without mapping it to an array.
So the algorithm is this make an array of [fizzbuzz fizz buzz x]. Then make an array of x mod 15, 3, 5.
Find the first instance of 0 in that second array and use that index to select fizz,buzz etc. If there isn't a zero (0 i. secondarray) returns the length of secondarray which is 3, the same index as x in the first array.
- acqq 10y agoThanks! So I made more than one bad guess. So >: can be monadic, increment and dyadic, bigger or equal. And i. can be a generator or an index of. But how to avoid reading the wrong meaning? If I'm reading right to left, I read 100, then I see i. then see something on the left of i. then why is it not a dyadic i. ? Because there is no parenthesis?
- Avshalom 10y agoIn this case i. is monadic because the thing to the left (>:) is a verb(function). It can get ugly because J has weird precedence/associative rules to let it be tacit but this isn't one of those cases >: Is monadic because I guess " is special? And has a higher precedence than other things?
- avmich 10y ago" is conjunction, it binds to its arguments - in this case left FB and right 0 - stronger than those bind to their arguments. >: is verb, i. another verb, so >: i. 100 is understood as >: (i. (100)) - as two monadic (one-argument) functions applied sequentially. To the left of that application sits the next verb - FB"0 which applied next, so the whole thing is FB"0 (>: (i. (100))) Precedence/associative rules are: all verbs from right to left, all adverbs/conjunctions from left to right, adverbs/conjunctions are higher by precedence than verbs. That's it.
- Avshalom 10y ago>Precedence/associative ... That's it. Until you get to hooks and forks.
- avmich 10y agoWell, we also didn't mention foreigns (like, functions dealing with OS), punctuation, predefined nouns. Hooks and forks also deserve a description, even though I don't think this is about "precedence/associative" matter - both hooks and forks as a whole are verbs, so verbs rules apply.
- klibertp 10y ago> But how to avoid reading the wrong meaning? The only thing other than "practice" you can do is to use built-in J expression pretty-printer. It shows you a graph of an expression, grouping verbs with their arguments. I don't remember how to get to it exactly, I think it was somewhere in foreigns. EDIT: it's even mentioned in the article, don't know how I missed it: 5!:4
- acqq 10y agoThanks. I've seen it but now that you mentioned I really liked to also understand what that means semantically: 5!:4 <'FB' I see here: http://www.jsoftware.com/help/dictionary/dx005.htm http://www.jsoftware.com/help/dictionary/dx005.htm That every combination of two numbers means something special. http://www.jsoftware.com/help/dictionary/dx018.htm http://www.jsoftware.com/help/dictionary/dx018.htm Wow.