Changes between Version 70 and Version 71 of Clojure Client Tutorial
- Timestamp:
- Aug 23, 2011 2:10:57 PM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Clojure Client Tutorial
v70 v71 25 25 * Clojure Docs [http://clojuredocs.org/]. 26 26 * Statistical Computing [http://incanter.org/] 27 * Marginalia (literate computing)[http://fogus.me/fun/marginalia/]27 * Literate Programming [http://fogus.me/fun/marginalia/] 28 28 * Pattern Matching and Predicate Dispatch [https://github.com/swannodette/match] 29 29 * Logic Programming [https://github.com/clojure/core.logic] … … 93 93 user=> (map inc [1 2 3 4 5]) 94 94 (2 3 4 5 6) 95 user=> (map (fn [e] (* e 2)) [1 2 3 4 5]) ; an anonymous function 95 user=> (map (fn [e] (* e 2)) [1 2 3 4 5]) ; an anonymous function that doubles its argument 96 96 (2 4 6 8 10) 97 97 user=> (map #(* % 2) [1 2 3 4 5]) ; same, but with alternative syntax 98 98 (2 4 6 8 10) 99 user=> ((juxt inc dec) 1)100 [2 0]101 }}}102 103 The client behaviour more closely corresponds to the "reduce" function.104 105 {{{106 99 user=> (reduce + [1 2 3 4 5]) 107 100 15 108 }}} 101 user=> (reduce #(cons %2 %1) (list) [1 2 3 4 5]) ; reverse a list 102 (5 4 3 2 1) 103 }}} 104 105 Another useful concept is that of "closures". Generally these appear in the context of a "let over lambda". For example, 106 107 {{{ 108 user=> (let [a (atom 0)] 109 (defn counter [] 110 (swap! a inc))) 111 #'user/counter 112 user=> (counter) 113 1 114 user=> (counter) 115 2 116 user=> (counter) 117 3 118 }}} 119 120 In this case, counter "closes" over the a lexical variable "a" and prevents it from going out of scope. 109 121 110 122 === Basic Functionality ===