Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

'explained' I read it twice and still don't understand what it's doing.


Author here. Sorry to hear that. If you want to let me know where I lost you via email or here, I'd be happy to revise it to be clearer.

I think it takes a certain skill to overcome the curse of already knowing something and then explaining it, and I'll definitely have some blind spots.

Thanks for reading it twice!


Consider that on HN there are surely people who read about J the first time, or if they have read something somewhere, they already forgot it and they won't go through the whole tutorial (which is not small) before reading the article.

For example, I guess that the

FB"0 >:i.100

is a kind-of for loop, even if I also guess it's not called as such in J, but I wouldn't be able to explain how it exactly works, except that >: is bigger or equal, which I glimpsed from some first page of the tutorial, and i. should mean index of, according to your text? But searching 100 in what? Or is it some new word?

Then, why was 1337 introduced in the explanation at all? I failed to understand, reading the text not too slowly.

Thanks for posting the article here, it's refreshing.


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.


Thanks! 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?


> 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


Thanks. 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

That every combination of two numbers means something special.

http://www.jsoftware.com/help/dictionary/dx018.htm

Wow.


In 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?


" 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.


>Precedence/associative ... That's it.

Until you get to hooks and forks.


Well, 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.


J makes my brain hurt, but in a much saner way than thisCamelCasedVariableNameIsNotNearlyLongEnoughToBeSufficientlyClear...WhereWasIGoing?

So, props.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: