Commits

Steven! Ragnarök  committed a9a3eec

Implement basic message sending and inbox printing.

  • Participants
  • Parent commits a85f5ef

Comments (0)

Files changed (3)

 .lein-failures
 checkouts
 .lein-deps-sum
+.redcar
 (defproject messageme "1.0.0-SNAPSHOT"
-  :description "FIXME: write description"
+  :description "A version of the messageme service
+  written in Clojure."
   :dependencies [[org.clojure/clojure "1.3.0"]])

File src/messageme/core.clj

 (ns messageme.core)
+
+(def message-box (agent []))
+
+(defn do-insert-message [message]
+  (send-off message-box (fn [box] (conj box message))))
+
+(defn send-message [sender recipient body]
+  (do-insert-message {:sender sender, :recipient recipient,
+  :body body}))
+  
+(defn inbox-data [uid]
+  (filter (fn [msg] (= (:recipient msg) uid)) @message-box))
+  
+(defn display-inbox [uid msgs]
+  (println (str "Inbox for " uid " contains " (count msgs) " messages:"))
+  (loop [[msg & remaining] msgs]
+    (if msg
+      (do
+        (println (str "  From: " (:sender msg) " | Message: " (:body msg)))
+      (recur remaining))
+    (println))))