6 ms·
It always felt strange to me that the main implementation of something as niche and esolang-adjacent as APL is neither OSS nor casually usable commercially, but
by gobdovan 5mo ago
It always felt strange to me that the main implementation of something as niche and esolang-adjacent as APL is neither OSS nor casually usable commercially, but instead comes under an enterprise license.
Anyway, I had a fun time a while ago translating APL programs to NumPy. At some point you get what APL is all about, and you can move on with life without too many regrets. Turns out most of the time it's more like a puzzle to get an (often inefficient) terse implementation by torturing some linear algebra operators.
If you're after a language that's OSS, has terse notation, and rewires your brain by helping you think more clearly instead of puzzle-solving, TLA+ is the answer.
Edit: if you're curious to see at a glance what APL is all about:
APL code:
(2=+⌿0=∘.|⍨⍳N)/⍳N <- this computes primes up to N and is presented as the 'Hello world' of APL.
Equivalent NUMPY code:
```
R = np.arange(1, N + 1) # ⍳N
divides = (R[None, :] % R[:, None]) == 0 # 0=∘.|⍨⍳N
divisor_counts = divides.sum(axis=0) # +⌿
result = R[divisor_counts == 2] # (2=...)/⍳N
```
As you can see, the famous prime generator is not even the Eratostenes' sieve, but a simple N^2 divisor counting computation.
- adamgordonbell 5mo agoBQN exists and needs more attention I think. It has some modern affordances as well. https://github.com/mlochbaum/BQN https://github.com/mlochbaum/BQN https://mlochbaum.github.io/BQN/doc/quick.html https://mlochbaum.github.io/BQN/doc/quick.html
- floxy 5mo agohttps://lamport.azurewebsites.net/tla/tla.html https://lamport.azurewebsites.net/tla/tla.html ?
- gobdovan 5mo agoYes! I put together some explanation and TLA+ related resources in this comment, the website is one of them: https://news.ycombinator.com/item?id=48075169 https://news.ycombinator.com/item?id=48075169
- blowscum 5mo ago> At some point you get what APL is all about, and you can move on with life without too many regrets. Honestly this is how computers/software/programming feel in general these days and it’s ruined it all for me.
- chillpenguin 5mo agoI basically feel the same way. In a way it is very liberating. All of those esoteric languages that were on my ever-growing todo list are now things I can let go of. Ultimately we have to ask ourselves how we want to spend our time, and now it is much harder to justify spending countless hours studying one programming language after another. We still can, of course, but we are now more "free" to do other things instead. It's sort of sad, but really I think it is a weight off my shoulders.
- tosh 5mo ago> Turns out most of the time it's more like a puzzle to get an (often inefficient) terse implementation by torturing some linear algebra operators. solutions in APL can be very efficient if they are written in a machine sympathetic way or in cases where the interpreter can map them onto one for the curious: https://aplwiki.com/wiki/Performance https://aplwiki.com/wiki/Performance https://www.youtube.com/watch?v=-6no6N3i9Tg https://www.youtube.com/watch?v=-6no6N3i9Tg (The Interpretive Advantage) https://ummaycoc.github.io/wc.apl/ https://ummaycoc.github.io/wc.apl/ (Beating C with Dyalog APL: wc)
- gobdovan 5mo agoThanks for the response. I'd interpret it as a valid technical caveat, but it feels somewhat orthogonal to what I was pointing out. You focus on the 'often inefficient' parenthetical, yet, to me, your response highlights the puzzle nature of the thinking APL encourages. If anything, it shifts the question from 'how do I express this tersely' to a still narrower 'how do I express this tersely in a way the interpreter can also optimize'.
- tosh 5mo agoI think every programming language to a degree has some kind of puzzle aspect I'm not sure APL has more or less of it compared to other languages for example in Python, even though the language has a concept of "There should be one-- and preferably only one --obvious way" (PEP 20) it is quite multi paradigm, which I think is a strength of Python oop, functional, imperative, … and you get tons of libraries to choose from e.g. numpy, pandas, polars, pytorch, keras, jax, … etc but you still also have to figure out the algorithm and data structures you want to use (like in any language) and you also kinda want to know (if you care about performance) how pytorch differs from numpy and how that differs from using a list with boxed values Not saying this is not the case with APL it definitely helps if you are familiar with the APL implementation you're using if you care about performance I just don't think it's a disadvantage of APL over other languages
- gobdovan 5mo ago
- tosh 5mo agorelated: blog post on fast primes in BQN https://panadestein.github.io/blog/posts/ps.html https://panadestein.github.io/blog/posts/ps.html
- shrubble 5mo agoIt’s not truly fair to call it an esolang given that it was used by mainframe customers for decades. It’s more like a less popular product than COBOL…
- wwweston 5mo ago> Turns out most of the time it's more like a puzzle to get an (often inefficient) terse implementation by torturing some linear algebra operators. In vector function space, no one can hear your eigen-scream.
- userbinator 5mo agobut instead comes under an enterprise license. The reason for this is because APL is quite popular in fintech, and of course that industry has no qualms about things not being free.
- xelxebar 5mo ago> At some point you get what APL is all about, and you can move on with life without too many regrets. Unfortunately, this seems to be a common experience. A lot of smart people only engage with APL via toy puzzles, like you did, and bounce off because that gives no insight about how to use the language in real life. IME, to really start getting APL you need to write and rewrite a full application 20 times. It helps to read code from the masters, too [0, 1, 2, 3, 4]. These all approach architecture in different ways: pedagogical FP style, OOP heavy, data-oriented design, event-driven state-machine, or a mix of the above. [0]:https://dfns.dyalog.com/ https://dfns.dyalog.com/ [1]:https://github.com/Co-dfns/MicroUI-APL https://github.com/Co-dfns/MicroUI-APL [2]:https://github.com/Dyalog/ewc https://github.com/Dyalog/ewc [3]:https://github.com/Co-dfns/Co-dfns https://github.com/Co-dfns/Co-dfns [4]:https://github.com/Dyalog/Jarvis/blob/master/Source/Jarvis.dyalog https://github.com/Dyalog/Jarvis/blob/master/Source/Jarvis.d... > As you can see, the famous prime generator is not even the Eratostenes' sieve, but a simple N^2 divisor counting computation. Well, that's because you wrote a divisor function, not a seive. Arguably, the ease of typing an outer product (i.e ∘.|⍨⍳N) can tempt us into writing quadratic algorithms unnecessarily, but this is just an experience issue, IMO. If we want a seive, we can just write one directly: p⊣{ω~n×1+⍳⌊N÷p⍪←n←ω↑⍨1⌊≢ω}⍣≡1↓1+⍳N⊣p←⍬ The algorithm is O(N log log N) as expected of a naive Eratosthenes implementation. You'll need ⎕IO←0 if you want to try it out. There's also a faster seive by Roger Hui [0] in the dfns workspace as well as a family of prime number functions [1] for things more than just prime generation. [0]:https://dfns.dyalog.com/n_sieve.htm https://dfns.dyalog.com/n_sieve.htm [1]:https://dfns.dyalog.com/n_pco.htm https://dfns.dyalog.com/n_pco.htm
- ofalkaed 5mo ago>A lot of smart people only engage with APL via toy puzzles I think part of this is because that is how most (possibly all) sources teach APL and array languages, solving puzzles and manipulating arrays. If you learn to write programs in an Algol derived language, you can write programs in most common languages without having to learn how to write programs, you just need to learn the language. Modern array languages sort of allow us to use them like the Algol derived languages, but this does not seem to work out so well and often does not work to the strengths of array languages.
- 5mo ago
- fnord77 5mo ago> If you're after a language that's OSS, has terse notation, and rewires your brain by helping you think more clearly I found MATLAB/Octave was good Matrix conjugate transpose: H = A';
- Ayush_Khati1 5mo ago[flagged]
- zerr 5mo agoIs it evaluated lazily? How about APL?