Permalink
Browse files

Mire: give preference to passing refs around that can be dereffed whe…

…n necessary
  • Loading branch information...
Andreas Pauley
Andreas Pauley committed Dec 24, 2009
1 parent 309fce7 commit 9b09b69d4c7b7b50c98095d18f968e521e0d4dcf
@@ -21,7 +21,7 @@
(binding [*player-name* (read-line)
*current-room* (ref (rooms :start))
*inventory* (ref #{})]
- (move-player-to (current-room))
+ (move-player-to @(current-room))
(println (look))
(print-prompt)
(loop [input (read-line)]
@@ -5,15 +5,15 @@
(defn look []
"Get a description of the current room"
(str "\n"
- (:desc (current-room))
+ (:desc @(current-room))
"\nInhabitants: " (current-inhabitants)
"\nItems: " (current-items)
- "\nExits: " (keys (:exits (current-room)))))
+ "\nExits: " (keys (:exits @(current-room)))))
(defn move
"We gotta get out of this place... Give a direction."
[direction]
- (let [target-name ((:exits (current-room)) (keyword direction))
+ (let [target-name ((:exits @(current-room)) (keyword direction))
target (rooms target-name)]
(if target
(do (move-player-to target)
@@ -25,7 +25,7 @@
(if (current-room-contains? thing)
(dosync
(move-between-refs (keyword thing)
- (:items (current-room))
+ (:items @(current-room))
*inventory*)
(str "You picked up the " thing "."))
(str "There isn't any " thing " here.")))
@@ -36,7 +36,7 @@
(dosync
(move-between-refs (keyword thing)
*inventory*
- (:items (current-room)))
+ (:items @(current-room)))
(str "You dropped the " thing "."))
(str "You are not carrying any " thing ".")))
@@ -21,25 +21,25 @@
(defn current-room []
"Returns the current room"
- @*current-room*)
+ *current-room*)
(defn current-inhabitants []
"Returns the inhabitants in the current room"
- @(:inhabitants (current-room)))
+ @(:inhabitants @(current-room)))
(defn current-items []
"Returns the items available in the current room"
- @(:items (current-room)))
+ @(:items @(current-room)))
(defn room-contains? [room thing]
(@(:items room) (keyword thing)))
(defn current-room-contains? [thing]
- (room-contains? (current-room) thing))
+ (room-contains? @(current-room) thing))
(defn move-player-to [target]
(dosync
(move-between-refs *player-name*
- (:inhabitants (current-room))
+ (:inhabitants @(current-room))
(:inhabitants target))
(ref-set *current-room* target)))

0 comments on commit 9b09b69

Please sign in to comment.