From ac6257a91cfaf1fd1e4ee2f53b830bd2d0aaa4c8 Mon Sep 17 00:00:00 2001 From: Michael Camilleri Date: Mon, 28 Jan 2019 13:48:04 +0900 Subject: [PATCH] Fix 'require' typo in Chapter 5 The code listing in Chapter 5 showing the namespace declaration for `pegthing.core` uses `(require` rather than `(:require`. This corrects that and updates the relevant `class` attribute in the code listing to be the appropriate value. --- content/cftbat/functional-programming.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/cftbat/functional-programming.html b/content/cftbat/functional-programming.html index 19db1dd6..af0554d8 100644 --- a/content/cftbat/functional-programming.html +++ b/content/cftbat/functional-programming.html @@ -350,13 +350,13 @@

Code Organization

Second, I’ve tried as much as possible to decompose tasks into small functions so that each does one tiny, understandable task. Some of these functions are used by only one other function. I find this helpful because it lets me name each tiny subtask, allowing me to better express the intention of the code.

But before all the architecture, there’s this:

(ns pegthing.core
-  (require [clojure.set :as set])
+  (:require [clojure.set :as set])
   (:gen-class))
 
 (declare successful-move prompt-move game-over query-rows)
 
-

I’ll explain the functions here in more detail in Chapter 6. If you’re curious about what’s going on, the short explanation is that (require [clojure.set :as set]) allows you to easily use functions in the clojure.set namespace, (:gen-class) allows you to run the program from the command line, and (declare successful-move prompt-move game-over query-rows) allows functions to refer to those names before they’re defined. If that doesn’t quite make sense yet, trust that I will explain it soon.

+

I’ll explain the functions here in more detail in Chapter 6. If you’re curious about what’s going on, the short explanation is that (:require [clojure.set :as set]) allows you to easily use functions in the clojure.set namespace, (:gen-class) allows you to run the program from the command line, and (declare successful-move prompt-move game-over query-rows) allows functions to refer to those names before they’re defined. If that doesn’t quite make sense yet, trust that I will explain it soon.

Creating the Board

The data structure you use to represent the board should make it easy for you to print the board, check whether a player has made a valid move, actually perform a move, and check whether the game is over. You could structure the board in many ways to allow these tasks. In this case, you’ll represent the board using a map with numerical keys corresponding to each board position and values containing information about that position’s connections. The map will also contain a :rows key, storing the total number of rows. Figure 5-3 shows a board with each position numbered.