Created
March 13, 2015 03:53
-
-
Save amacdougall/8956ea4fb9286dd9bde3 to your computer and use it in GitHub Desktop.
ClojureScript sample code
This file contains 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
;; Some examples of Clojure syntax. ClojureScript is almost entirely identical | |
;; to Clojure. | |
;; Anything preceded by semicolons is a comment. Double-semicolons are | |
;; generally doc comments; single semicolons are developer comments. | |
(def message "Hello world!") | |
message ; simply naming something returns its value | |
;; Familiar array type, called a "vector"; cannot be lazy | |
(def pokemon ["Pikachu" "Charizard" "Squirtle" "Bulbasaur" "Magikarp" "Jigglypuff"]) | |
;; List: slightly different behavior, can be lazy, is a Sequence | |
(def more-pokemon '("Mewtwo" "Caterpie" "Psyduck" "Slowpoke")) | |
;; Familiar key-value hash, called a "map" | |
(def alan {:first-name "Alan" | |
:last-name "MacDougall" | |
:class "Developer" | |
:stats {:strength 9 | |
:dexterity 8 | |
:constitution 12 | |
:intelligence 15 | |
:wisdom 8 | |
:charisma 10} | |
:equipment {:chest {:type :shirt, :armor 0, :quality :average} | |
:legs {:type :jeans, :armor 0, :quality :average} | |
:feet {:type :shoes, :armor 0, :quality :fine}}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment