Permalink
Browse files

Mire: introduce move-between-refs

  • Loading branch information...
1 parent c028a29 commit e5b892d8f1ea6b57ecc09cff38cefd758ccc8d43 Andreas Pauley committed Dec 23, 2009
Showing with 11 additions and 3 deletions.
  1. +5 −3 PeepCode/Clojure/mire/src/mire/rooms.clj
  2. +6 −0 PeepCode/Clojure/mire/src/mire/util.clj
@@ -1,4 +1,5 @@
-(ns mire.rooms)
+(ns mire.rooms
+ (:use [mire util]))
(declare rooms)
@@ -33,6 +34,7 @@
(defn move-player-to [target]
(dosync
- (alter (:inhabitants (current-room)) disj player-name)
- (alter (:inhabitants target) conj player-name)
+ (move-between-refs player-name
+ (:inhabitants (current-room))
+ (:inhabitants target))
(ref-set *current-room* target)))
@@ -3,3 +3,9 @@
(defn print-flush [text]
(print text)
(flush))
+
+(defn move-between-refs
+ "Move one instance of obj between from and to. Must be called in a transaction."
+ [obj from to]
+ (alter from disj obj)
+ (alter to conj obj))

0 comments on commit e5b892d

Please sign in to comment.