Clojure’s most salient characteristic is that it is a Lisp
Clojure recognizes two kinds of structures: Literal representations of data structures (like numbers, strings, maps, and vectors) Operations
Operations are how you do things. All operations take the form opening parenthesis, operator, operands, closing parenthesis:
Clojure uses whitespace to separate operands, and it treats commas as whitespace
if This is the general structure for an if expression: (if boolean-form then-form optional-else-form)
The do operator lets you wrap up multiple forms in parentheses and run each of them. Try the following in your REPL: (if true (do (println "Success!") "By Zeus's hammer!") (do (println "Failure!") "By Aquaman's trident!")) ; => Success! ; => "By Zeus's hammer!"
The when operator is like a combination of if and do, but with no else branch. Here’s an example: (when true (println "Success!") "abra cadabra") ; => Success! ; => "abra cadabra"
Use when if you want to do multiple things when some condition is true, and you always want to return nil when the condition is false.
You can check if a value is nil with the appropriately named nil? function:
Both nil and false are used to represent logical falsiness
(if "bears eat beets" "bears beets Battlestar Galactica") ; => "bears beets Battlestar Galactica" (if nil "This won't be the result because nil is falsey" "nil is falsey") ; => "nil is falsey"
Clojure’s equality operator is =:
You use def to bind a name to a value in Clojure:
(def failed-protagonist-names ["Larry Potter" "Doreen the Explorer" "The Incredible Bulk"]) failed-protagonist-names ; => ["Larry Potter" "Doreen the Explorer" "The Incredible Bulk"]
Clojure comes with a handful of data structures that you’ll use the majority of the time
All of Clojure’s data structures are immutable, meaning you can’t change them in place
Clojure has pretty sophisticated numerical support
Suffice it to say, Clojure will merrily handle pretty much anything you throw at it.
Maps are similar to dictionaries or hashes
The two kinds of maps in Clojure are hash maps and sorted maps
Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.