News for hackers. Stuff that matters.
Re:k on pdp11 by Pompidou on Monday January 08, 2024 @12:18PM (#38915114)
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)

Re:k on pdp11 by nerdponx on Monday January 08, 2024 @04:11PM (#38918192)
> 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.

Re:k on pdp11 by abrudz on Monday January 08, 2024 @04:02PM (#38918058)
That's not Eratosthene's sieve, but rather a naive O(n²) algorithm, implementing "a prime never occurs in the multiplication table".
Re:k on pdp11 by moonchild on Monday January 08, 2024 @05:21PM (#38919101)
> 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).

Re:k on pdp11 by omaranto on Monday January 08, 2024 @11:23PM (#38922283)
I think (-.*/~)2}.i.100 is a little more idiomatic.