From 545a11a662e598e70e05fa7a1fcd1d05d76a3942 Mon Sep 17 00:00:00 2001 From: Alvaro Garcia Date: Wed, 21 Oct 2015 11:04:15 +0200 Subject: [PATCH 1/2] manual cherry pick of map syntax to master --- src/intro-clojure/basics.clj | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/intro-clojure/basics.clj b/src/intro-clojure/basics.clj index 55467c7..aae07d5 100644 --- a/src/intro-clojure/basics.clj +++ b/src/intro-clojure/basics.clj @@ -204,5 +204,19 @@ ;; 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))) ) From bd75de6dbcec05532f984b4fb304b45f3e9578a5 Mon Sep 17 00:00:00 2001 From: Alvaro Garcia Date: Wed, 21 Oct 2015 11:08:04 +0200 Subject: [PATCH 2/2] add syntax guide for lambda --- src/intro-clojure/basics.clj | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/intro-clojure/basics.clj b/src/intro-clojure/basics.clj index aae07d5..af72acf 100644 --- a/src/intro-clojure/basics.clj +++ b/src/intro-clojure/basics.clj @@ -199,7 +199,23 @@ (+) ;; 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