diff --git a/src/intro-clojure/basics.clj b/src/intro-clojure/basics.clj index 55467c7..af72acf 100644 --- a/src/intro-clojure/basics.clj +++ b/src/intro-clojure/basics.clj @@ -199,10 +199,40 @@ (+) ;; count a's in a sentence - ;; ??? should #(%) be introduced? + ;; lambda syntax + + ;; a #() is the syntax for the lambda + (#(-> 3)) ; 3 + + (#(inc %) 1) ;2 + + (#(= % %) 1) ;true + (#(= % %) 2) ;true... always true + + ; syntax for the first, second parameter + (#(= %1 %2) 10 11) ;false + (#(= %1 %2) 10 10) ;true + + ; syntax for the first parameter + (#(= % %2) 10 10) ;true + (count (filter #(= \a %) "mama")) ;; squares (take 10 (map #(* % %) (range))) + + ;; explain map syntax + + ;; map syntax + ;; remember + (= + (inc 1) + 2) + + ;;simpler + (map inc [1 2 3]) + + ;;more difficult + (take 10 (map inc (range))) )