Skip to content

Instantly share code, notes, and snippets.

@nathany
Created September 21, 2009 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathany/190435 to your computer and use it in GitHub Desktop.
Save nathany/190435 to your computer and use it in GitHub Desktop.
based on hello from Stuart Halloway's book
;; 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