Conway's Game Of Life in APL
Dyalog11 HN recommenders · recommended in 10 months, 2010–2024
demo · intro · evergreen · 2010–2024 on HN
A short Dyalog demonstration building Conway's Game of Life in a single line of APL, step by step. It shows how array operations replace loops.
Recommended whenever APL or array languages come up as the quickest way to see why the paradigm is so striking.
Up next
1 mo on HNCompiling and Optimizing Scripting Languages
Google TechTalks
1 HN recommend · 2011–2020
5 mo on HNSimon Peyton Jones: Data Parallel Haskell
nuACM
5 HN recommender · 2010–2017
5 mo on HNP vs. NP and the Computational Complexity Zoo
hackerdashery
4 HN recommender · 2015–2026
1 mo on HNLucas Cavalcanti & Edward Wible - Exploring four hidden superpowers of Datomic
ClojureTV
1 HN recommend · 2015–2024
12 mo on HNReverse emulating the NES to give it SUPER POWERS!
suckerpinch
12 HN recommender · 2018–2025
4 mo on HNRustLatam 2019 - Without Boats: Zero-Cost Async IO
Rust Programming Language
5 HN recommender · 2019–2020
3 mo on HNCraig Ferguson Speaks From The Heart
Monke96ify
3 HN recommender · 2014–2026
5 mo on HNTed Nelson demonstrates Xanadu Space
photonhunter
5 HN recommender · 2011–2022
16 mo on HNHow Python was Shaped by leaky Internals, Armin Ronacher, Flask framework
Видео с мероприятий {speach!
15 HN recommender · 2017–2025
12 mo on HNWhy Isn't Functional Programming the Norm? – Richard Feldman
Metosin
12 HN recommender · 2019–2025
11 mo on HNMaybe Not - Rich Hickey
ClojureTV
14 HN recommender · 2018–2025
9 mo on HNLecture 1A | MIT 6.001 Structure and Interpretation, 1986
MIT OpenCourseWare
11 HN recommender · 2012–2024
12 comments from Hacker News
> Here's a video that really illustrates the power of this paradigm: ▶ this video Amazing game of life code!
Try watching this video; it will only take you 8 minutes, but within 3 minutes you should have an idea of why array languages are different from having an ndarray library available in Rust or having typeclasses in Haskell: ▶ this video After you watch that you will of course suspect that APL and other array languages like J are a sort of DSL for things like numerical linear algebra, which is of course what Numpy and Octave are. (Even though the Game of Life isn't linear algebra, it's very clearly matrix-based, so it doesn't seem that far off.) Dyalog has posted some other videos demonstrating the use of their proprietary APL for different things, but I think a more interesting one is link , by J inventor Roger Hui. This is an hour and a half, but it demonstrates some approaches to reducing different problems to multidimensional arrays, of pointers ("boxes") in some cases. This ought to be enough to convince you that there's an alien kind of thinking here, quite different from the Haskell and Rust approaches, that can be applied to a wide variety of problems. Now, I'm not Stevan Apter, so I'm not going to try to convince you that this alien kind of thinking is better . But it's clearly different , and different ways of thinking work best in different situations.
The following video is probably reasonably well known, and I wish that I had a more intelligent commentary than to say that it blows my mind, but it does I think bear out the point of expressivity rather well. ▶ this video Conway's Game of Life in some 50 characters of APL.
While we wait for the site to come back up please enjoy this amazing video showing Conway's Game of Life in APL: ▶ this video
It has an incredible amount of elegant power for some things (see ▶ this video if you want to immediately fall in love). But I've found that trying to use it for most things just isn't worthwhile. It feels like cheating every time I have to escape from its array programming core to the more familiar flow control structures that only came along in later versions of APL. I think it makes a good puzzle language (i.e. the fun comes from figuring out _how_ to say something rather that just raw getting stuff done), but unfortunately, it's even more of a puzzle to figure out how code that someone else wrote works. For full context: I've spent more time using J than APL itself.
Seems then you'll probably dislike apl - here's the full implementation of Conway's Game of Life in 53 characters: life ← {⊃1 ⍵ ∨.∧ 3 4 = +/ +⌿ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵} And the explanatory video behind it (quite approachable!) ▶ this video
> My point was that general programming usually looks more like writing the sorting algorithm than simply calling it. Thus, I would be more interested in seeing real examples of how the properties of J allow you to write algorithms more concisely or otherwise better. Ah - I see. Here[1] is quicksort in j. John scholes's videos are excellent and very illustrative, though they deal with apl rather than j; conway's game of life[2] and sudoku[3]. > The article showed how J solves some mathematical problems with built in functions or their built-in modifiers. But in general programming, you won't find a function that does exactly what you wanted, maybe with a little adverb. You'll usually have to write that function yourself, to describe how it works in terms of some of those pre-existing functions. Right. This is true, but you generally stay much closer to the builtins in j than you do in other language. > Note that your second example could be expressed as something like > x.OrderBy(y => y[1]) > In C#, assuming x is int[N][M]. I understand that J's version can work with many other shapes of X, but that is hard to appreciate without seeing example of how that comes in handy when writing some other (hopefully well known) algorithm. Right; you mentioned sort predicates, so I was giving an example of a way in which you could sort according to another relation. My point is: being able to change the layout of your data so easily can obviate sort predicates. (Though I do think a sort a
APL (and I assume J) uses a large range of special graphic symbols as part of its syntax, which can be difficult to internalize for folks coming from other languages. It can be easily construed as mysterious or magical lettering (arcane rune). My favorite video to illustrate this is Conway's Game of Life written in APL: ▶ this video
I think the key to understanding APL is realizing that it’s not built for Programmers; it’s built for Mathematicians. Here’s a fine half-hour introduction to APL in action: link 1:00-2:00 is the motivation for APL—or any DSL—in a nutshell. (“conversational computing”, “users who are [not] professional programmers”) Or, if you’re happy to sit back and see math magic happen: ▶ this video For all its mechanical advances over the last 40 years, it’s shocking how far our technology has regressed philosophically.
I always liked this example: Conway's Game of Life in One Line of APL ▶ this video It's esoteric as one-liners tend to be, but I think it's a fascinating glimpse.
For an infinitely more relaxing experience of life in APL, may I recommend: ▶ this video I've watched it many times but I still expect him to mention happy little trees :)
Would you prefer something like this numpy then? def life(x): y = np.array([np.roll(x, -1), np.roll(x, 0),np.roll(x, 1)]) y = np.array([np.roll(y, -1, 1), np.roll(y, 0, 1),np.roll(y, 1, 1)]) z = y.sum(1).sum(0) a = np.array([3 == z, 4==z]) c = np.logical_and(np.array([np.ones(x.shape), x]), a) return np.logical_or(c[0], c[1]) Video of Scholes building up the life APL expression can be seen here: ▶ this video