⬆️ ⬇️

Conway's “life” of each letter, only in Emacs!

One working December evening





We all one way or another faced with the game "Life" Conway . Someone wrote himself, someone watched and marveled, someone played ...



On the new year, sitting with a colleague at the same computer and solving some problem at the end of the working day, we moved away a bit from the problem and somehow it came down to Mx life (we both use Emacs), whoever is unfamiliar with Emacs is the Emacs toy launch team.

')

Standard is not interesting




It seems to be something to talk about. Yes, only the implementation in Emacs has about 10 “embedded” initial positions, which, to put it mildly, are not interesting.



Do you know that:









Hands were combed




My hands were itching to try some of the interesting forms of the game. But for this you need to do something so that the implementation of the life function perceives the current text in the text editor window, and not insert one of its “beautiful” templates.



And, looking at the life function code (by clicking on 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 designed 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 was just the code of our function starts to “live”.







But the glider , the emblem of hackers :



Source: https://habr.com/ru/post/136597/



All Articles