News for hackers. Stuff that matters.
Re:FizzBuzz in J, Explained by caioariede on Thursday January 19, 2017 @04:04PM (#13439477)
I think comparing it with other languages may make it easier to grasp. Sometimes it's good to test it in a language you are used to. The selector expression could be represented in Python like this:

  a = lambda n: [n % x for x in [15, 3, 5]].index(0)
Re:FizzBuzz in J, Explained by 101km on Thursday January 19, 2017 @04:08PM (#13439510)
Yep, I started writing this out (first in js, but it doesn't map well, python list comprehensions do) but you beat me to it. :)

Now great, you can get the weird syntax and unroll it if you squint. Why is it written like this? Isn't it wasteful to test against all three cases (15,3,5) instead of returning early?

Probably has something to do with 'thinking in arrays' and how its a cheap comparison and that there's probably matrix multiplication or bit twiddling going on under there. That's the interesting bit to me.

To get the feel for an array language. This fizzbuzz example is actually surprisingly interesting because of that.

Re:FizzBuzz in J, Explained by caioariede on Thursday January 19, 2017 @04:13PM (#13439551)
In fact, it's still not the same. In Python, the following expression will raise a ValueError.

  > a(2)
In J, it will return the length of the array, as stated in the post.