|
APL was amazing for the time, but array-oriented programming is mainstream now, while the notation never really caught on. A lot of the mystique of APL is because it's illegible, but at the end of the day it's nothing more than a DSL for 'numpy-like' code. You can code the same demo, in the same amount of time, using Julia, and the result is (in my opinion) much more legible: The opaque one-liner: using IterTools,ImageInTerminal,Colors;for g in iterated(a->let n=sum(map(t->circshift(a,t),product(-1:1,-1:1)));(a.&(n.==4)).|(n.==3);end,rand(Bool,(99,99)));imshow(map(Gray,g));print("\n\n");end The legible version where we give everything descriptive names so it's not cryptic and mysterious: using ImageInTerminal,Colors #the APL demo also uses a library for pretty display
using IterTools #okay *technically* this is a minor cheat
function nextgen(grid)
neighborcount = sum(map((t)->circshift(grid,t), product(-1:1,-1:1)))
return (grid .& (neighborcount .== 4)) .| (neighborcount .== 3)
end
function animate(grid)
for gen in iterated(nextgen, grid)
imshow(map(Gray, gen))
print("\n\n")
sleep(0.05)
end
end
animate(rand(Bool,(100,100)))
|
I still think learning mathematical symbols is better than spelling out mathematical formulas and likewise APL and J to me allow the same power of abstraction; it just takes some effort to learn them. A lot of friction is learning something new.