Since my previous post on APL and J I’ve read the 45 or so pages of Easy J and am quite impressed by this nifty language. It may seem strange at first, but is very logically structured and not difficult to understand at all. That said I still need to constantly have the vocabulary open to write anything remotely useful, but I’m slowly starting to remember more and more of it.
Here are a couple of examples of J’s expressiveness, with the first two based on exercises from our “Core Ruby” course on RubyLearning.org.
How old is a person if he/she is 1 billion seconds old?
1 2 |
|
Using Antibase (#:) it’s easy to see that the answer is 31 years, 259 days, 1 hour, 46 minutes and 40 seconds.
Convert degress Fahrenheit to degrees Celsius.
1 2 3 |
|
Divide by 1.8 after (Atop, @) subtracting 32. I suspect there’s a better way to write this, but it’s the first thing that came to my mind…
Create a sorted set from a list of numbers.
1 2 3 |
|
Sort (/:) the distinct items (nub) of the list. Don’t concern yourself too much with the passive (~) for now, it’s just there so the arguments to take end up in the right spot.
That’s it for today, in my next post on J I want to focus on the language’s excellent plotting capabilities.