The other day, I learnt about how, when bash does arithmetic expansion, it evaluates variables as a whole arithmetic expression, instead of just an int; which leads to crazy fast[1] recursive “functions” being completely doable.
As a normal adult with a life, I have totally been reasonable with my new found hammer that is so, so, so, so beautiful, and pretty, and useful, and there’s just… so many nails around to hit I can’t believe my luck-
A-hem, anyway: k8s3dnih9's solution for Conway's Game of Life in Bash on Exercism
I tried my best to keep things labeled understandably, at the very least. Beyond the recursion stuffs, it’s a fairly basic bit mask approach, I added a whole paragraph at the end explaining it.
Overall, I do think it’s a feature of bash(and ksh too, apparently) that has been seemingly around since forever ago but had gone rather underappreciated. (not for a lack of reasons tho: set -x is useless here, and I sure had a blast debugging all that, but still!)
since the slower bash interpreter only has to evaluate the command once ↩︎