This is Conway's Game of Life, written in Guile, an implementation of the Scheme programming language. To augment the more idiomatic Scheme implementation on Rosetta Code, this version explores how one deals with the more day-to-day aspects of software development in Guile, such as:
- Code organisation with modules
- Encapsulation with closures and message passing
- Unit testing
- IO
Load it up into the interpreter with guile -l gameoflife.scm
. Functions exposed are:
game-of-life
: function that creates the game of life closure, which can receive the following messages:(setgrid! grid)
: storesgrid
(a list of list of 0s and 1s) into the game(getgrid)
: gets the current pattern from the game(step!)
: increments the generation
pretty-print-grid
: converts a grid to a more readable stringgrid-from-file
: loads up a grid from filesend
: sugar function for sending a messagenew-instance
: sugar function for instantiating a new closure
See tests (below) for usage.
Uses srfi-64
, an API for writing test suites. The Guile 2.0 port is by Sunjong Lee, also included in this repository for convenience. Copy it into the site packages directory, where third party Scheme files should be placed:
sudo cp ./srfi-64-guile/srfi/srfi-64.scm /usr/share/guile/site/2.0/srfi/srfi-64.scm
Run tests with
guile -l gameoflife.scm gameoflife-test.scm
and output should be written to game_logic.log
and utility_functions.log
Scheme newbie here, so contributions on better ways of doing things are welcome!