Hacker News new | past | comments | ask | show | jobs | submit login
Conway's Game of Life in APL in Forth (github.com/chmykh)
78 points by todsacerdoti on May 30, 2022 | hide | past | favorite | 25 comments



There is a really excellent podcast on Array programming languages. https://www.arraycast.com/


Fascinating. And given that GoL is Turing complete, it should be theoretically possible to implement a Turing machine in the cellular automaton that could then run a copy of the Forth interpreter running the APL program running the CA.


Please make your Turing complete game of life execute arbitrary Lisp code and you will have rescued the holy grail of computer language hacker nerdom here.


Hmmmmmm.

Native port of SectorLISP (https://justine.lol/sectorlisp/) to the Quest for Tetris processor (https://codegolf.stackexchange.com/questions/11880/build-a-w...), anybody?

SectorLISP is x86-specific, so this wouldn't just be neatly mushing existing things together, but I think the result could be very interesting nonetheless. I'm tempted to note that SectorLISP's tiny size could make this a reasonable one-shot/nerdsnipe-sized weekend project :D


I might need to learn APL. It seems like I'm missing out on something. Lisp was a gift which helped with my C and Elixir. That was a mini-revelation in itself.


APL, K or J ; I've learned APL, and was able to use it effectively - but things only really "clicked" when I learned K; And despite several attempts, J never did click for me -- not sure why, probably the associations I have for the ascii characters are too strong to break.

But yes, highly recommend learning members of this family. It will help your C for sure as well, though possibly not in ways you'd expect.

After using APL and K for a while, I realized 95% of "abstraction" features in C++ / C# and friends are useless; I now avoid C++; My C code became way shorter, way more efficient, way simpler -- but also much less orthodox.


What do you recommend to learn APL and K?


Try “Learning APL” —- https://xpqz.github.io/learnapl

Disclaimer: I’m the author


Thanks. Will check it out.


From https://en.wikipedia.org/wiki/K_%28programming_language%29

Here's their example:

The following expression sorts a list of strings by their lengths:

x@>#:'x

Ooooooookay. Personally, I recommend a lot of alcohol. This will be a very wild and geeky ride. Bring extra pizza.


Personally, I recommend less alcohol.

Pronounced, this would be "x at grade-down of count of each x" - and indeed, in "q" (a syntactic sugar for K that uses words instead of symbols), this is almost how you would write it (rather: "x at downgrade count each x". It's basically algorithmic math notation: In math you say "b^2-4ac" rather than "b squared minus 4 times a times c". In K you say "x@>#:'x".

It's not just a matter of symbol/syntax familiarity - there's also idioms, etc. But the "scariness" is similar to the "scariness" of a language like Japanese or Arabic, which uses different graphic elements, syntax, vocabulary, and idioms. You might not like it, but it's not because there's something weird or wrong about it -- it's just foreign.


Sounds like a recipe for alcohol addiction and obesity. Otherwise maybe I'd try that. ;)


I learned APL on a mainframe over 30 years ago, which is not something I'd recommend (also, you're unlikely to have access to one), but rumor says Dyalog has good tutorials, such as "Mastering Dyalog APL", see links here https://www.dyalog.com/getting-started.htm

As for K, Stefan Kruger's text seems like a good introduction https://xpqz.github.io/kbook/Introduction.html


Thanks. Will check these out.


I’ve written a few things on APL and K for the learner. Links here:

https://xpqz.github.io/about/


A Beautiful bit of coding.


tl;dr - a 200 line implementation of Life together with a heavily annotated version of the same thing. Might get you into APL or scare you off, more likely.


Well. It's a 1 line implementation in APL. The 200 lines are there so that Forth can emulate enough of APL to execute the 1-liner.


This video is what should get you into APL

https://youtu.be/_DTpQ4Kk2wA


I love that demo! I want something like that, but much more modern. I already have demo video ready – https://youtu.be/y5Tpp_y2TBk?t=18


I'm a sucker for GPT3.

In his weekly column the famous IT philosopher explains issues in computation in a very thoughtful manner.

Recently, Conway's Game of Life was implemented as a one-liner in APL executed in FORTH. APL is another weird-looking programming language. Implementing Conway's game of Life yet again is important because it is a fundamental example of a computation. In this case, the one-liner is important because it is an example of how to concisely express a computation.

Conway's Game of Life is a cellular automaton. A cellular automaton is a discrete model of computation. It consists of a grid of cells, each of which can be in one of a finite number of states. The state of the automaton is updated in discrete time steps, according to a fixed rule. In Conway's Game of Life, the rule is that a cell is alive in the next time step if and only if it was alive in the previous time step and exactly two or three of its eight neighbors were also alive. If a cell is not alive in the previous time step, then it is alive in the next time step if and only if exactly three of its neighbors were alive.

The one-liner in APL executes the Game of Life rule on a two-dimensional grid of cells. The input to the one-liner is the state of the grid at some time step, and the output is the state of the grid at the next time step. The one-liner is able to do this because it uses a clever trick. It treats the input grid as a one-dimensional array of cells, and it uses the fact that the Game of Life rule can be expressed as a matrix operation.

The one-liner is:

life←{↑1 ⍵∨.↑1 3 4⍵}

This one-liner is an example of how to concisely express a computation. It is also an example of how to use a powerful programming language to express a computation in a simple and elegant way.


That looks like a butchered version of

      life ← {⊃1 ⍵ ∨.∧ 3 4 = +/ +⌿ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵}
as shown at https://aplwiki.com/wiki/Conway%27s_Game_of_Life


Whoever wrote that is much smarter than me!


I didn't notice it initially but (part of) the two top lines are italicized. Presumably this was the input prompt.

Which is kind of cool to be able to look at and observe that it made that from just those specific 48 input words. Huh.


It isn't so much a "the author of that one liner is way smarter" but rather "the language features of APL naturally fit this problem space."




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: