Tutorial by Examples: clojure

clojure.spec/and & clojure.spec/or can be used to create more complex specs, using multiple specs or predicates: (clojure.spec/def ::pos-odd (clojure.spec/and odd? pos?)) (clojure.spec/valid? ::pos-odd 1) ;;=> true (clojure.spec/valid? ::pos-odd -3) ;;=> false or works similarl...
You can call a Clojure function from Java code by looking up the function and invoking it: IFn times = Clojure.var("clojure.core", "*"); times.invoke(2, 2); This looks up the * function from the clojure.core namespace and invokes it with the arguments 2 & 2.
Add a :cljsbuild node like the following to your project.clj file. :cljsbuild { :builds { ;;Different target goals should have different names. ;;We have the dev build here :dev { ;;The ClojureScript c...
(defn x [a b] (* a b)) ;; public function => (x 3 2) ;; 6 => (x 0 9) ;; 0 (defn- y [a b] (+ a b)) ;; private function => (x (y 1 2) (y 2 3)) ;; 15
When applied on a map, returns a new map with new or updated key val pairs. It can be used to add new information in existing map. (def userData {:name "Bob" :userID 2 :country "US"}) (assoc userData :age 27) ;; { :name "Bob" :userID 2 :country "US&qu...
Comparisons are functions in clojure. What that means in (2>1) is (> 2 1) in clojure. Here are all the comparison operators in clojure. Greater Than (> 2 1) ;; true (> 1 2) ;; false Less Than (< 2 1) ;; false Greater Than or Equal To (>= 2 1) ;; true (>= 2 ...
This returns a map without the key-value pairs for the keys mentioned in the function argument. It can be used to remove information from existing map. (dissoc {:a 1 :b 2} :a) ;; {:b 2} It can also be used for dissocing multiple keys as: (dissoc {:a 1 :b 2 :c 3} :a :b) ;; {:c 3}

Page 1 of 1