Mercurial > dylan
view chat/room.clj @ 2:b4de894a1e2e
initial import
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 28 Oct 2011 00:03:05 -0700 |
parents | |
children |
line wrap: on
line source
1 (ns chat.room2 (:use [clojure.contrib server-socket duck-streams str-utils])3 (:gen-class))6 ;; CHAT ROOMS8 (def rooms (ref {}))10 (defn get-room! "Returns the chat room with the given name, creating it if necessary." [name]11 (dosync12 (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 ;; USERS24 (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 room34 )