Clojure
Functions
Multi-arity functions
defn messenger
("Hello world!"))
([] (messenger println msg))) ([msg] (
anonymous functions
fn [message] (println message))
(
;; Equivalent to: (fn [x] (+ 6 x))
+ 6 %)
#(
;; Equivalent to: (fn [x y & zs] (println x y zs))
println %1 %2 %&)
#(
apply f '(1 2 3 4)) ;; same as (f 1 2 3 4) (
Java interoperability
Instantiation | new Widget("foo") | (Widget. "foo") |
Instance method | rnd.nextInt() | (.nextInt rnd) |
Instance field | object.field | (.-field object) |
Static method | Math.sqrt(25) | (Math/sqrt 25) |
Static field | Math.PI | Math/PI |
Data Structures
- Lists are akin to linked-lists
- Vectors are C++ vectors