A Clojure Snake

The Snake game features a player-controlled snake that moves around a game grid hunting for an apple. When your snake eats an apple, it grows longer by a segment, and a new apple appears. If your snake reaches a certain length, you win. But if your snake crosses over its own body, you lose.

Before you start building your own snake, take a minute to try the completed version. Follow the instructions in the README file at the root of the sample code for the book to start a REPL, then enter the following:

 (require '[examples.snake :refer :all])
 
 (game)

Select the Snake window and use the arrow keys to control your snake.

Our design for the snake takes advantage of Clojure’s functional nature and its support for explicit mutable ...

Get Programming Clojure, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.