
Conway's “Life” from every letter, only in Emacs!
One working December evening
One way or another, we all came across the Conway game “Life” . Someone wrote himself, someone looked and wondered, someone played ...
On New Year's Eve, sitting with a colleague at the same computer and solving some kind of problem at the end of the working day, we moved away from the problem a bit and somehow it came together to Mx life (we both use Emacs), & emdash; anyone new to Emacs is the team to launch the Life toy in Emacs.
Standard uninteresting
It seems to be something to talk about. Yes, that's just the implementation in Emacs has about 10 "wired" initial positions, which are uninteresting to say the least.
Do you know that:
Conway initially suggested that no initial combination could lead to unlimited reproduction and offered a $ 50 bonus to someone who would prove or disprove this hypothesis.
- quote from Wikipedia;To date, the following classification of figures has more or less developed:
- quote from Wikipedia;- Emacs is an extensible text editor.
Hands combed
My hands were combed over to try some of the interesting forms of the game. But for this, something needs to be done so that the implementation of the life function perceives the current text in the text editor window, rather than inserting one of its “beautiful” templates.
And, having looked at the code of the life function (by clicking in Emacs Chf life ), it turned out that everything is simple:
(defun xlife ()
(interactive)
(let ((life-patterns (vector (list (buffer-string)))))
(life)))
The xlife function is intended to bind the string-contents of the current buffer to the global dynamic variable life-patterns , which is used by the life function . And then just do the last one.
No copying of the implementation, no hooks and hacks. We load the
code of our function in Emacs ( CMx ) and execute ( Mx xlife ): the text that has just been the code of our function begins to “live”.
And here is the glider , the emblem of hackers :