Created
September 21, 2009 18:33
-
-
Save nathany/190435 to your computer and use it in GitHub Desktop.
based on hello from Stuart Halloway's book
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; reference to a set (unique) visitors | |
(def visitors (ref #{})) | |
(defn hello | |
"Writes hello message to *out*. Calls you by username. | |
Knows if you have been here before." | |
([] (hello "world")) ; with no arguments | |
([username] | |
(dosync | |
;; deref visitors, call username to see if it's there | |
(let [past-visitor (@visitors username)] | |
(if past-visitor | |
(str "Welcome back, " username) | |
;; else | |
(do | |
;; conjoin (append) an element | |
(alter visitors conj username) | |
(str "Hello, " username))))))) | |
(hello "Nathan") | |
(hello "Nathan") | |
(hello) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment