4 ms·
I've just discovered array/ matrix languages, and especially J. It's so a pleasure to use it. I struggle since a long time to use python or r for their mixed sc
by Pompidou 3y ago
I've just discovered array/ matrix languages, and especially J. It's so a pleasure to use it. I struggle since a long time to use python or r for their mixed scalar/array style. K/J/apl are so clean and well designed in this regard.
For instance: Eratosthene's sieve to get all prime under 100 :
"
(-.] * /])2}.i.100
"
Another great property of J is his natural language like structure :
without =: -.
multiplied_by =: */
upto =: 4 : 'x}.i.1+y'
Sieve_100 =:
(2 upto 100) without (2 upto 100) multiplied_by (2 upto 100)
- abrudz 3y agoThat's not Eratosthene's sieve, but rather a naive O(n²) algorithm, implementing "a prime never occurs in the multiplication table".
- nerdponx 3y ago> mixed scalar/array style For whatever it's worth, R specifically is almost entirely arrays, with the exception of NULL. Even language constructs like functions, including source code itself, are represented as heterogeneous arrays (called "lists"). I'd go so far as to claim that R is an homoiconic array language.
- moonchild 3y ago> upto =: 4 : 'x}.i.1+y' Fyi: for a while now, j has supported the more convenient 'direct definition' syntax. You can now write that definition like: upto =: {{ x}.i.1+y }} It will automatically make a monad or a dyad depending on whether you use x or not (or an adverb or a conjunction if you use u or m or v or n).
- omaranto 3y agoI think (-.*/~)2}.i.100 is a little more idiomatic.