Last active
August 29, 2015 14:01
-
-
Save smt/be44832893256101f7f4 to your computer and use it in GitHub Desktop.
Clojure learnings...
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
;; 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! |
Do you have the generated js?
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
Referenced in this tweet:
https://twitter.com/tagsoup/status/464779932019998720