view chat/room.clj @ 11:1f112b4f9e8f tip

Fixed what was baroque.
author Dylan Holmes <ocsenave@gmail.com>
date Tue, 01 Nov 2011 02:30:49 -0500
parents b4de894a1e2e
children
line wrap: on
line source
1 (ns chat.room
2 (:use [clojure.contrib server-socket duck-streams str-utils])
3 (:gen-class))
6 ;; CHAT ROOMS
8 (def rooms (ref {}))
10 (defn get-room! "Returns the chat room with the given name, creating it if necessary." [name]
11 (dosync
12 (or (@rooms name)
13 (let [new-room (agent '())]
14 (do (alter *rooms* assoc name new-room))))))
16 (defn say-in-room[room message]
17 (doseq [[_ output] room]
18 (binding [*out* output]
19 (println message))))
22 ;; USERS
24 (defn user-join[room username output-channel]
25 (conj room [username output-channel]))
26 (defn user-leave[room username]
27 (remove #(= (% 0) username) room))
30 (def *username* "Someone")
31 (defn- join-room [room]
32 (send room user-join *username* *out*)
33 (send room
34 )