|
1 | 1 | <!-- -*- mode: markdown ; mode: visual-line ; coding: utf-8 -*- --> |
2 | 2 |
|
| 3 | +# Changes to Clojure in Version 1.7 |
| 4 | + |
| 5 | +## 1 New and Improved Features |
| 6 | + |
| 7 | +### 1.1 Transducers |
| 8 | + |
| 9 | +Transducers is a new way to decouple algorithmic transformations from their |
| 10 | +application in different contexts. Transducers are functions that transform |
| 11 | +reducing functions to build up a "recipe" for transformation. |
| 12 | + |
| 13 | +Also see: http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming |
| 14 | + |
| 15 | +Many existing sequence functions now have a new arity (one fewer argument |
| 16 | +than before). This arity will return a transducer that represents the same |
| 17 | +logic but is independent of lazy sequence processing. Functions included are: |
| 18 | + |
| 19 | +* conj (conjs to []) |
| 20 | +* map |
| 21 | +* mapcat |
| 22 | +* filter |
| 23 | +* remove |
| 24 | +* take |
| 25 | +* take-while |
| 26 | +* drop |
| 27 | +* drop-while |
| 28 | +* cycle |
| 29 | +* take-nth |
| 30 | +* replace |
| 31 | +* partition-by |
| 32 | +* partition-all |
| 33 | +* keep |
| 34 | +* keep-indexed |
| 35 | + |
| 36 | +Additionally some new transducer functions have been added: |
| 37 | + |
| 38 | +* cat - concatenates the contents of each input |
| 39 | +* de-dupe - removes consecutive duplicated values |
| 40 | +* random-sample - returns items from coll with random probability |
| 41 | + |
| 42 | +And this function can be used to make completing transforms: |
| 43 | + |
| 44 | +* completing |
| 45 | + |
| 46 | +There are also several new or modified functions that can be used to apply |
| 47 | +transducers in different ways: |
| 48 | + |
| 49 | +* sequence - takes a transformation and a coll and produces a lazy seq |
| 50 | +* transduce - reduce with a transformation (eager) |
| 51 | +* iteration - returns an iterable/seqable/reducible seq of applications of the transducer to items in coll. Applications are re-performed with every iterator/seq/reduce. |
| 52 | +* run! - run the transformation for side effects on the collection |
| 53 | + |
| 54 | +There have been a number of internal changes to support transducers: |
| 55 | + |
| 56 | +* volatiles - there are a new set of functions (volatile!, vswap!, vreset!, volatile?) to create and use volatile "boxes" to hold state in stateful transducers. Volatiles are faster than atoms but give up atomicity guarantees so should only be used with thread isolation. |
| 57 | +* array iterators - added support for iterators over arrays |
| 58 | + |
| 59 | +Some issues created and addressed during development: |
| 60 | +* [CLJ-1511](http://dev.clojure.org/jira/browse/CLJ-1511) |
| 61 | +* [CLJ-1497](http://dev.clojure.org/jira/browse/CLJ-1497) |
| 62 | + |
| 63 | +### 1.2 Keyword and Symbol Construction |
| 64 | + |
| 65 | +In response to issues raised in [CLJ-1439](http://dev.clojure.org/jira/browse/CLJ-1439), |
| 66 | +several changes have been made in symbol and keyword construction: |
| 67 | + |
| 68 | +1) The main bottleneck in construction of symbols (which also occurs inside keywords) was |
| 69 | +interning of the name and namespace strings. This interning has been removed, resulting |
| 70 | +in a performance increase. |
| 71 | + |
| 72 | +2) Keywords are cached and keyword construction includes a cache check. A change was made |
| 73 | +to only clear the cache reference queue when there is a cache miss. |
| 74 | + |
| 75 | +### 1.3 Warn on Boxed Math |
| 76 | + |
| 77 | +One source of performance issues is the (unintended) use of arithmetic operations on |
| 78 | +boxed numbers. To make detecting the presence of boxed math easier, a warning will now |
| 79 | +be emitted about boxed math if \*unchecked-math* is enabled. |
| 80 | + |
| 81 | +Example use: |
| 82 | + |
| 83 | + user> (defn plus-2 [x] (+ x 2)) ;; no warning, but boxed |
| 84 | + #'user/plus-2 |
| 85 | + user> (set! *unchecked-math* true) |
| 86 | + true |
| 87 | + user> (defn plus-2 [x] (+ x 2)) ;; now we see a warning |
| 88 | + Boxed math warning, NO_SOURCE_PATH:10:18 - call: public static java.lang.Number |
| 89 | + clojure.lang.Numbers.unchecked_add(java.lang.Object,long). |
| 90 | + #'user/plus-2 |
| 91 | + user> (defn plus-2 [^long x] (+ x 2)) ;; use a hint to avoid boxing |
| 92 | + #'user/plus-2 |
| 93 | + |
| 94 | +* [CLJ-1325](http://dev.clojure.org/jira/browse/CLJ-1325) |
| 95 | + |
| 96 | +### 1.4 update - like update-in for first level |
| 97 | + |
| 98 | +`update` is a new function that is like update-in specifically for first-level keys: |
| 99 | + |
| 100 | + (update m k f args...) |
| 101 | + |
| 102 | +Example use: |
| 103 | + |
| 104 | + user> (update {:a 1} :a inc) |
| 105 | + {:a 2} |
| 106 | + user> (update {:a 1} :a + 2) |
| 107 | + {:a 3} |
| 108 | + user> (update {} :a identity) ;; missing returns nil |
| 109 | + {:a nil} |
| 110 | + |
| 111 | +* [CLJ-1251](http://dev.clojure.org/jira/browse/CLJ-1251) |
| 112 | + |
| 113 | +## 2 Enhancements |
| 114 | + |
| 115 | +### 2.1 Error messages |
| 116 | + |
| 117 | +* [CLJ-1261](http://dev.clojure.org/jira/browse/CLJ-1261) |
| 118 | + Invalid defrecord results in exception attributed to consuming ns instead of defrecord ns |
| 119 | +* [CLJ-1169](http://dev.clojure.org/jira/browse/CLJ-1169) |
| 120 | + Report line,column, and source in defmacro errors |
| 121 | + |
| 122 | +### 2.2 Documentation strings |
| 123 | + |
| 124 | +No changes. |
| 125 | + |
| 126 | +### 2.3 Performance |
| 127 | + |
| 128 | +* [CLJ-1430](http://dev.clojure.org/jira/browse/CLJ-1430) |
| 129 | + Improve performance of partial with more unrolling |
| 130 | +* [CLJ-1384](http://dev.clojure.org/jira/browse/CLJ-1384) |
| 131 | + clojure.core/set should use transients for better performance |
| 132 | +* [CLJ-1429](http://dev.clojure.org/jira/browse/CLJ-1429) |
| 133 | + Cache unknown multimethod value default dispatch |
| 134 | + |
| 135 | +### 2.4 Other enhancements |
| 136 | + |
| 137 | +* [CLJ-1191](http://dev.clojure.org/jira/browse/CLJ-1191) |
| 138 | + Improve apropos to show some indication of namespace of symbols found |
| 139 | +* [CLJ-1378](http://dev.clojure.org/jira/browse/CLJ-1378) |
| 140 | + Hints don't work with #() form of function |
| 141 | +* [CLJ-1498](http://dev.clojure.org/jira/browse/CLJ-1498) |
| 142 | + Removes owner-thread check from transients - this check was preventing some valid usage of transients in core.async where a transient is created on one thread and then used again in another pooled thread (while still maintaining thread isolation). |
| 143 | + |
| 144 | +## 3 Bug Fixes |
| 145 | + |
| 146 | +* [CLJ-1362](http://dev.clojure.org/jira/browse/CLJ-1362) |
| 147 | + Reduce broken on some primitive vectors |
| 148 | +* [CLJ-1388](http://dev.clojure.org/jira/browse/CLJ-1388) |
| 149 | + Equality bug on records created with nested calls to map->record |
| 150 | +* [CLJ-1274](http://dev.clojure.org/jira/browse/CLJ-1274) |
| 151 | + Unable to set compiler options via system properties except for AOT compilation |
| 152 | +* [CLJ-1241](http://dev.clojure.org/jira/browse/CLJ-1241) |
| 153 | + NPE when AOTing overrided clojure.core functions |
| 154 | +* [CLJ-1185](http://dev.clojure.org/jira/browse/CLJ-1185) |
| 155 | + reductions does not check for reduced value |
| 156 | +* [CLJ-1039](http://dev.clojure.org/jira/browse/CLJ-1039) |
| 157 | + Using def with metadata {:type :anything} throws ClassCastException during printing |
| 158 | +* [CLJ-887](http://dev.clojure.org/jira/browse/CLJ-887) |
| 159 | + Error when calling primitive functions with destructuring in the arg vector |
| 160 | +* [CLJ-823](http://dev.clojure.org/jira/browse/CLJ-823) |
| 161 | + Piping seque into seque can deadlock |
| 162 | +* [CLJ-738](http://dev.clojure.org/jira/browse/CLJ-738) |
| 163 | + <= is incorrect when args include Double/NaN |
| 164 | + |
3 | 165 | # Changes to Clojure in Version 1.6 |
4 | 166 |
|
5 | 167 | ## CONTENTS |
|
0 commit comments