6 ms·
If anyone is interested in a more readable version of APL, I think python/numpy qualifies. Their first few examples can be expressed the same way in standard nu
by yummyfajitas 10y ago
If anyone is interested in a more readable version of APL, I think python/numpy qualifies. Their first few examples can be expressed the same way in standard numpy:
arange(6) # Same as ⍳5
add.reduce(arange(6)) # Same as +/⍳5
add.accumulate(arange(6)) # Same as +\⍳5
I've gone partway through this document (up to chapter 3, plus skimming other bits) and have not found any examples that don't translate into standard numpy code.
From what I can tell, the core learning one takes from J/K/etc is the concept of an array language and treating arrays as first class objects. And nowadays Python/R/Julia provide this same functionality in a more verbose/more readable/more mainstream package.
- _mhr_ 10y agoIt'd be a fun project to write a an APL-like that compiles down to NumPy. Would it be pointless? Another interesting project might be to make an APL-like for probabilistic programming.
- yummyfajitas 10y agoMy point is that it'd be pretty easy. The semantics are pretty close, it's only the syntax ("+/" -> "add.reduce") that varies.
- 3JPLW 10y agoThere's a start for this in Julia[0], where custom string literals mean that you can actually write APL in native Julia: julia> apl"ι5" 1:5 julia> apl"+/ι5" 15 You can even just get the function that represents the `+/` operation and apply it to any Julia object: julia> apl"+/"(rand(100)) 52.17866879741195 0. https://github.com/shashi/APL.jl https://github.com/shashi/APL.jl
- beagle3 10y ago> From what I can tell, the core learning one takes from J/K/etc is the concept of an array language and treating arrays as first class objects. And nowadays Python/R/Julia provide this same functionality in a more verbose/more readable/more mainstream package. That's just part of it. Other parts (by no means a complete list): - Visual density puts the pattern matching engine in your brain to good use; e.g. the K idiom "|/0(0|+)+\" which implements maximum-subsequence-sum is a 10-character visually recognizable sequence recognizable to many K programmers, which is efficient and well specified; Similarly, ",//" flattens a list. I don't know of any other language family that has this feature. - Arrays with equivalent indices work better than structures ("column major" captures some, but not all of it) - A properly selected core set of concrete operations (in K's case, about 60 of them) makes the needed abstractions shallower and simpler than a properly selected set of abstraction constructs.
- yummyfajitas 10y agoI agree that Python/R/Julia don't have the same visual density. But your second point is definitely something that Python/R/Julia do - that's why data frames (e.g. Pandas) are so popular. Can you suggest something that K does beyond this? By the way, I'm not asking to criticize K. I really want to know of there is something I'm missing. I've investigated J a bit, but never found the enlightenment that people say I'll find.
- beagle3 10y ago> Can you suggest something that K does beyond this? I'm not familiar enough with pandas to say for sure that K is way better - but I was familiar enough with numpy back in the day, and that was definitely way too clunky and cumbersome compared to K. But look at e.g. advent-of-code solutions on https://kx.com/2016/01/04/puzzle-solutions-for-advent-of-code/ https://kx.com/2016/01/04/puzzle-solutions-for-advent-of-cod... - I suspect even pandas won't be able to use vector correspondence so succinctly.