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)))
[go to top]