zlacker

[return to "Notation as a Tool of Thought"]
1. sxp+ck[view] [source] 2020-11-30 04:45:25
>>mafaa+(OP)
For those unfamiliar with the power of APL, see this demo of someone livecoding the Game of Life: https://www.youtube.com/watch?v=a9xAKttWgP4

Its modern descendent are https://en.wikipedia.org/wiki/J_(programming_language) & https://en.wikipedia.org/wiki/K_(programming_language).

◧◩
2. dTal+ip2[view] [source] 2020-11-30 20:52:12
>>sxp+ck
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)))
◧◩◪
3. eggy+Wc3[view] [source] 2020-12-01 03:14:38
>>dTal+ip2
I would argue that numpy is a dsl for apl-like code. APL and J are based on arrays at the fundamental level. J inspired Pandas per Pandas' creator.

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.

[go to top]