Skip to content

Instantly share code, notes, and snippets.

@smt
Last active August 29, 2015 14:01
Show Gist options
  • Save smt/be44832893256101f7f4 to your computer and use it in GitHub Desktop.
Save smt/be44832893256101f7f4 to your computer and use it in GitHub Desktop.
Clojure learnings...
;; let expression is an IIFE (provides lexical scope)
(let [name "Vick"
msg "Much appreciated"]
(println (str "Thanks, " name))
(println msg))
;; => Thanks, Vick
;; => Much appreciated!
;; anonymous function definition can be treated as an IIFE
((fn [name msg]
(println (str "Thanks, " name))
(println msg)) "Vick" "Much appreciated!")
;; => Thanks, Vick
;; => Much appreciated!
;; shorter syntax for an anonymous IIFE
(#((println (str "Thanks, " %1))
(println %2)) "Vick" "Much appreciated!")
;; => Thanks, Vick
;; => Much appreciated!
;; named function expression, to be invoked later
(defn thx [name msg]
(println (str "Thanks, " name))
(println msg))
(thx "Vick" "Much appreciated!")
;; => Thanks, Vick
;; => Much appreciated!
@smt
Copy link
Author

smt commented May 9, 2014

@vickaita
Copy link

vickaita commented May 9, 2014

Do you have the generated js?

@smt
Copy link
Author

smt commented May 9, 2014

I am surprised the initial version worked at all (misplaced parens) :)

http://clojurescriptkoans.com is quite entertaining.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment