Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/intro-clojure/basics.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

)