Skip to content

Commit

Permalink
Mire: introduce move-between-refs
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Pauley committed May 26, 2010
1 parent c028a29 commit e5b892d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions PeepCode/Clojure/mire/src/mire/rooms.clj
@@ -1,4 +1,5 @@
(ns mire.rooms)
(ns mire.rooms
(:use [mire util]))

(declare rooms)

Expand Down Expand Up @@ -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)))
6 changes: 6 additions & 0 deletions PeepCode/Clojure/mire/src/mire/util.clj
Expand Up @@ -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.