9 ms·
I really like Ivy as a simple, friendly introduction to APL. There is a surprising lack of APL-derived languages that use words to name things -- most stick wit
by ianthehenry 4y ago
I really like Ivy as a simple, friendly introduction to APL. There is a surprising lack of APL-derived languages that use words to name things -- most stick with the original symbols; J and friends choose equally-cryptic symbols composed of ASCII characters.
Earlier this year I decided to solve AoC 2021 in Ivy, then watch Russ Cox's videos to see how he did it and use that to learn something about array programming -- a topic I knew absolutely nothing about going into this.
Unfortunately, Ivy really is, as Rob Pike says, a plaything. It is buggy -- if you ever write a function that returns a vector or a higher-rank array, you are entering bizarre undefined behavior territory. The array-language equivalent of "concat_map" or "flat_map" or "mapcat" or whatever you want to call it just produces garbage values, which is very confusing when you're learning about array programming for the first time ("Wait, this vector says its length is 25, but it contains 50 elements...?" or "The transpose of this array is just the first column repeated over and over??").
Beyond that, a very cool thing about array languages is that, you know, functions can implicitly act on entire arrays. You can multiple a vector by 2 and it will know to multiply every element in the vector by 2, because multiplication is defined for scalars.
But in Ivy, this is only true for the built-in functions. There is no way to write user-defined functions that have this implicit act-on-every-element behavior. Which is basically the looping primitive in array languages -- so to do anything nontrivial, you have to write it out with explicit recursion (still with the caveat that your functions can only return scalars, or you enter undefined behavior town) or rewrite your operations as binary operations with an ignored right-hand side and use "fold" to "map" them. It's bad.
The latter is crippling enough that Russ Cox eventually forks Ivy to add support for it, but it is not currently part of the language. https://github.com/robpike/ivy/pull/83 https://github.com/robpike/ivy/pull/83
Anyway that's a long comment to say: Ivy is a good, friendly introduction to APL syntax (stranding, ambivalent functions, precedence, etc) and some array language concepts, but it is far more of a calculator than a programming language.
But it's a good arbitrary-precision calculator! And if you're still interested in trying it, maybe check out this thing I made. It's an... Ivy programming environment?... that lets you run Ivy scripts and see the results inline. (Ivy's repl is... very primitive, and has to be wrapped by something like readline. Russ Cox uses 9term to get around this; self-modifying programs are my preferred approach.)
https://github.com/ianthehenry/privy https://github.com/ianthehenry/privy
My frustration with Ivy led me to look into other array languages, trying to find one that 1) used English words instead of cryptic symbols and 2) worked. And I really couldn't find any! Someone should do something about that. :)
- mlochbaum 4y agoI believe Nial fits the bill here? It has some symbols, but less than most C-family languages. https://www.nial-array-language.org/ https://www.nial-array-language.org/
- ianthehenry 4y agoYou know, I discounted Nial prematurely because its array model seemed weird and different and -- still not actually knowing anything about array languages -- I became very enamored with J's ability to slice and reassemble arrays based on function rank, which is something that I thought Nial could not do (I don't actually remember why I thought this). I should actually read through the Nial docs and see what I've been missing.
- mlochbaum 4y agoNial uses the nested array model, which arguably is weird, but is also shared by every surviving APL dialect that supports nesting. J's boxed model comes from SHARP APL, but A+ was the only other language to pick it up and both those have stopped development. https://aplwiki.com/wiki/Array_model https://aplwiki.com/wiki/Array_model And it sounds like you've found it, but Nial does have the RANK transformer, which looks essentially the same as J's rank conjunction " .
- 7thaccount 4y agoThe q and k languages are part of the commercial Kdb+ array database that all the major banks use for rapid analysis. Seriously cool stuff and probably the state of the art in array programming. Kdb+ also has dashboards and other useful things. The original creator left to form his own company called shaktiDB, so that is another commercial product. Dyalog APL is the most advanced true APL out there. Unfortunately, you may notice a trend here that all the best tech in this space is currently commercial and closed source. That's a major deal breaker for some and for good reason.
- rak1507 4y ago'There is a surprising lack of APL-derived languages that use words to name things' - This isn't really surprising when you consider the history of APL, and what it was designed for. Arguably you could say something like numpy is APL derived (or at least inspired), and that uses words. I think if you tried APL for a bit, you'd quickly get over the symbols (and even come to prefer them eventually).