from Hacker News

KlongPy: High-Performance Array Programming in Python

by cl3misch on 12/2/24, 6:40 AM with 78 comments

  • by nils-m-holm on 12/2/24, 4:29 PM

    Good to see KlongPy thrive! It is based on Klong (http://t3x.org/klong/), which I do not maintain any more, so I am glad that Brian took over!
  • by dang on 12/2/24, 6:07 PM

    Related. Others?

    KlongPy: Vectorized port of Klong array language - https://news.ycombinator.com/item?id=35400742 - April 2023 (8 comments)

    Klong: a Simple Array Language - https://news.ycombinator.com/item?id=21854793 - Dec 2019 (73 comments)

    Statistics with the array language Klong - https://news.ycombinator.com/item?id=15579024 - Oct 2017 (12 comments)

    Klong – a simple array language - https://news.ycombinator.com/item?id=10586872 - Nov 2015 (21 comments)

  • by kstrauser on 12/2/24, 4:01 PM

    This is awesome. I’ve wanted to play with array languages before but they tend to be kind of a pain in the neck to start with locally. I like the idea of hacking my way around in the new language while keeping a Python escape hatch close by in case I haven’t yet learned how to do a thing the new way.

    Nice.

  • by faizshah on 12/2/24, 5:41 PM

    I’ve tried several times to give J/k/Q/kdb a chance but I haven’t really found a convincing example why this approach is better than say SQL or say numpy/jax etc.

    The syntax has the same problem as perl in that you have to learn too many symbols that are hard to look up. And this combined with the tacit style makes it difficult to parse what the code is doing.

    I think ruby went in the radically opposite direction in that it provides a similar feature set to perl with similar functional features but everything is human readable text. I feel like there’s room for a human readable version of J that relies less on syntactical sugar.

    I do think the direction Klong has gone with the syntax is an improvement: https://t3x.org/klong/ambiguity.html

    I’m curious if anyone has a go-to article/example of why an array language would be a good choice for a particular problem over other languages?

    I know the second chapter of J for C programmers is kinda like that but I didn’t really find it convincing: https://www.jsoftware.com/help/jforc/culture_shock.htm#_Toc1...

  • by eismcc on 12/2/24, 5:34 PM

    KlongPy author here: AMA
  • by amarcheschi on 12/2/24, 4:44 PM

    I'm gonna be the one who asks the dumb question, but someone has to do it: why are expressions evaluated from right to left?
  • by solidsnack9000 on 12/2/24, 3:33 PM

    I gather where it says `:monad` it is referring to an operation that had an effect on the interpreter state?
  • by incrudible on 12/2/24, 3:36 PM

    Naive array programming is not really high performance in my book, because performing a lot of trivial arithmetic on large arrays leads to poor locality and high bandwidth pressure. The better alternative is SPMD, i.e. something like CUDA or ISPC for CPUs. This is possible with some type of JIT if the numpy style of programming is to be maintained, for example tinygrad.
  • by cturner on 12/2/24, 5:33 PM

    I would love something like duolingo, but for an array language. Not a steady series of challenging puzzles like leetcode sites, Rather, a series of questions with high repetition, somewhat like flash cards, easy to drop into for a few minutes.
  • by behnamoh on 12/2/24, 5:15 PM

    What are some real-world practical applications of array programming? Because as far as I know, APL did not catch on, and its subsequent versions like J and K and BNQ also did not become useful in industry. Maybe there's something I'm missing. Why would you want to do array programming in Python? What are the advantages over regular Python programming?
  • by RestartKernel on 12/2/24, 10:56 PM

    I've been meaning to give something APL-ish a shot, but I don't see how such languages can be justified in a non-academic engineering environment. I doubt any company would like to limit themselves to hiring programmers who are capable of maintaining such code.
  • by MPSimmons on 12/2/24, 4:14 PM

    I thought I knew python, but then I saw this:

        ?> sum::{+/x}  :" sum + over / the array x
        :monad
        ?> sum([1 2 3])
        6
        ?> count::{#x}
        :monad
        ?> count([1 2 3])
        3
    
    What?