News for hackers. Stuff that matters.
Re:Zoo of Array Languages by fainpul on Tuesday October 14, 2025 @09:24AM (#45579736)
I assume this is the same as this?

  # python
  [127 * sin(x * tau * freq / samplerate) for x in range(samplerate)]
Re:Zoo of Array Languages by zahlman on Tuesday October 14, 2025 @09:39AM (#45579917)
For that matter,

  # python
  from numpy import sin, arange, pi
  127 * sin(arange(samplerate) * 2 * pi * freq / samplerate)
Re:Zoo of Array Languages by kelas on Wednesday October 15, 2025 @03:12PM (#45597079)
for that matter, i always wonder how people mistake python for numpy :) they have surprisingly little in common.

but enough talking about languages that suck. let's talk about python!

i'm not some braniac on a nerd patrol, i'm a simple guy and i write simple programs, so i need simple things. let's say i want an identity matrix of order x*x.

nothing simpler. i just chose one of 6 versions of python found on my system, create a venv, activate it, pip install numpy (and a terabyte of its dependencies), and that's it - i got my matrix straight away. i absolutely love it:

  np.tile(np.concatenate([[1],x*[0]]),x)[:x*x].reshape(*2*[x])
and now lets see just how obscure and unreadable exactly the same thing looks in k:

  (2#x)#1,x#0
no wonder innocent people end up with brain aneurisms and nervous breakdowns.
Re:Zoo of Array Languages by RodgerTheGreat on Wednesday October 15, 2025 @04:56PM (#45598296)
i'm a fan of

    t=\:t:!x
Re:Zoo of Array Languages by kelas on Thursday October 16, 2025 @06:27AM (#45603694)
nice :) also see here:

https://news.ycombinator.com/item?id=45603661

HN is such a sweetheart. i should check in more often.

Re:Zoo of Array Languages by kelas on Thursday October 16, 2025 @06:38AM (#45603756)
> t=\:t:!x

this is of course obvious first idea, but the recipe from above is actually from the official k4 cookbook. t=t is less innocent than it seems, i'm afraid.

in k7/k9, we can:

  10^@[100#0.;11*!10;1.]    /just for more lulz
there's also a way to mutate it in place!
Re:Zoo of Array Languages by seanhunter on Thursday October 16, 2025 @04:16AM (#45602755)
That is wildly disingenuous. Assuming you've imported numpy as np, you get an nxn identity matrix by doing

   np.identity(n)

http://numpy.org/doc/stable/reference/generated/numpy.identi...
Re:Zoo of Array Languages by kelas on Thursday October 16, 2025 @06:24AM (#45603661)
> That is wildly disingenuous.

assuming you're referring to numpy as to have anything to do with python spec, i totally agree with you. only it doesn't. so don't pytorch and pandas (and good so, poor python doesn't need any extra help to be completely f).

> you get an nxn identity matrix by...

no, man, that's how you get it. really advanced technique, kudos!

i get it by:

   id:{...}     /there are many ways to implement identity in k, and it's fun!
   id 3
  +1.00 +0.00 +0.00
  +0.00 +1.00 +0.00
  +0.00 +0.00 +1.00
but if you can keep a secret, more recently we've gotten so lazy and disingenuous in k land, and because we need them bloody matrices so often now, we just do it like so:

   &3
  +1.00 +1.00 +1.00
  +1.00 +1.00 +1.00
  +1.00 +1.00 +1.00

   =3
  +1.00 +0.00 +0.00
  +0.00 +1.00 +0.00
  +0.00 +0.00 +1.00
(but of course before we do that we first install python4, numpy, pytorch, pandas and polars - not because we need them, just to feel like seasoned professionals who know what they're doing)
Re:Zoo of Array Languages by thristian on Tuesday October 14, 2025 @09:36AM (#45579890)
Pretty much, yeah! The difference is that in Python the function that calculates a single value looks like:

    foo(x)
...while the function that calculates a batch of values looks like:

    [foo(x) for x in somelist]
Meanwhile in Lil (and I'd guess APL and K), the one function works in both situations.

You can get some nice speed-ups in Python by pushing iteration into a list comprehension, because it's more specialised in the byte-code than a for loop. It's a lot easier in Lil, since it often Just Works.

Re:Zoo of Array Languages by RodgerTheGreat on Tuesday October 14, 2025 @09:59AM (#45580130)
A few more examples in K and Lil where pervasive implicit iteration is useful, and why their conforming behavior is not equivalent to a simple .map() or a flat comprehension: http://beyondloom.com/blog/conforming.html
Re:Zoo of Array Languages by leephillips on Tuesday October 14, 2025 @10:11AM (#45580230)
And in Julia it’s foo.(x).
Re:Zoo of Array Languages by kelas on Thursday October 16, 2025 @09:01AM (#45604801)
julia is cool, hands down.

only typical k binary will be less than 200kb and doesn't need stdlib. it still needs a few syscalls, but we're working on that.

and julia has this small and insignificant dependency called llvm. i bullshit you not:

  kelas@prng ~ % cd /opt/llvm-project
  kelas@prng llvm-project % du -hd0
   14G .
  kelas@prng llvm-project %