Clojure 1.7.0-beta1 is now available.
Try it via
- Leiningen: [org.clojure/clojure "1.7.0-beta1"]
Regression fixes since 1.7.0-alpha6:
1) CLJ-1692 - make iterate match prior laziness
2) CLJ-1694 - make cycle match prior laziness
3) CLJ-1685 - correctly handle :eof option in read and read-string
One faster sequence and reduce path that didn't quite make it into alpha6 is now available - range is now faster for both the traditional sequence use case (both chunked and unchunked traversal) and the fast reduce path.
Also, since alpha6 was released, reader conditionals were ported to tools.reader and the latest ClojureScript release now supports them, so now is a great time to try them out!
For all changes new in beta1, see the issues marked "(beta1)" in the
full changes below.
------------------------------------------------------------
Clojure 1.7.0-beta1 has the following updates since 1.6.0:
# Changes to Clojure in Version 1.7
## 1 New and Improved Features
### 1.1 Transducers
Transducers is a new way to decouple algorithmic transformations from their
application in different contexts. Transducers are functions that transform
reducing functions to build up a "recipe" for transformation.
Many existing sequence functions now have a new arity (one fewer argument
than before). This arity will return a transducer that represents the same
logic but is independent of lazy sequence processing. Functions included are:
* conj (conjs to [])
* map
* mapcat
* filter
* remove
* take
* take-while
* drop
* drop-while
* take-nth
* replace
* partition-by
* partition-all
* keep
* keep-indexed
* map-indexed
* distinct
* interpose
Additionally some new transducer functions have been added:
* cat - concatenates the contents of each input
* de-dupe - removes consecutive duplicated values
* random-sample - returns items from coll with random probability
And this function can be used to make completing transforms:
* completing
There are also several new or modified functions that can be used to apply
transducers in different ways:
* sequence - takes a transformation and a coll and produces a lazy seq
* transduce - reduce with a transformation (eager)
* eduction - returns a reducible/iterable of applications of the transducer to items in coll. Applications are re-performed with every reduce/iterator.
* run! - run the transformation for side effects on the collection
There have been a number of internal changes to support transducers:
* 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.
* array iterators - added support for iterators over arrays
Some related issues addressed during development:
### 1.2 Reader Conditionals
Reader Conditionals are a new capability to support portable code that
can run on multiple Clojure platforms with only small changes. In
particular, this feature aims to support the increasingly common case
of libraries targeting both Clojure and ClojureScript.
Code intended to be common across multiple platforms should use a new
supported file extension: ".cljc". When requested to load a namespace,
the platform-specific file extension (.clj, .cljs) will be checked
prior to .cljc.
A new reader form can be used to specify "reader conditional" code in
cljc files (and *only* cljc files). Each platform defines a feature
identifying the platform (:clj, :cljs, :cljr). The reader conditional
specifies code that is read conditionally based on the feature/
Form #? takes a list of alternating feature and expression. These are
checked like cond and the selected expression is read and returned. Other
branches are unread. If no branch is selected, the reader reads nothing
(not nil, but literally as if reading ""). An optional ":default" branch
can be used as a fallthrough.
Reader conditional with 2 features and a default:
#?(:clj Double/NaN
:cljs js/NaN
:default nil)
There is also a reader conditional splicing form. The evaluated expression
should be sequential and will be spliced into the surrounded code, similar
to unqoute-splicing.
For example:
[1 2 #?@(:clj [3 4] :cljs [5 6])]
This form would read as [1 2 3 4] on Clojure, [1 2 5 6] on ClojureScript,
and [1 2] on any other platform.
Additionally, the reader can now be invoked with options for the features
to use and how to interpret reader conditionals. By default, reader conditionals
are not allowed, but that can be turned on, or a "preserve" mode can be used to
preserve all branches (most likely useful for tooling or source transforms).
In the preserve mode, the reader conditional itself and any tagged literals
within the unselected branches are returned as tagged literal data.
For more information, see:
### 1.3 Keyword and Symbol Construction
several changes have been made in symbol and keyword construction:
1) The main bottleneck in construction of symbols (which also occurs inside keywords) was
interning of the name and namespace strings. This interning has been removed, resulting
in a performance increase.
2) Keywords are cached and keyword construction includes a cache check. A change was made
to only clear the cache reference queue when there is a cache miss.
### 1.4 Warn on Boxed Math
One source of performance issues is the (unintended) use of arithmetic operations on
boxed numbers. To make detecting the presence of boxed math easier, a warning will now
be emitted about boxed math if \*unchecked-math* is set to :warn-on-boxed (any truthy
value will enable unchecked-math, only this specific value enables the warning).
Example use:
user> (defn plus-2 [x] (+ x 2)) ;; no warning, but boxed
#'user/plus-2
user> (set! *unchecked-math* :warn-on-boxed)
true
user> (defn plus-2 [x] (+ x 2)) ;; now we see a warning
Boxed math warning, NO_SOURCE_PATH:10:18 - call: public static java.lang.Number
clojure.lang.Numbers.unchecked_add(java.lang.Object,long).
#'user/plus-2
user> (defn plus-2 [^long x] (+ x 2)) ;; use a hint to avoid boxing
#'user/plus-2
### 1.5 update - like update-in for first level
`update` is a new function that is like update-in specifically for first-level keys:
(update m k f args...)
Example use:
user> (update {:a 1} :a inc)
{:a 2}
user> (update {:a 1} :a + 2)
{:a 3}
user> (update {} :a identity) ;; missing returns nil
{:a nil}
### 1.6 Faster reduce and iterator paths
Several important Clojure functions now return sequences that also
contain fast reduce() (or in some cases iterator()) paths. In many
cases, the new implementations are also faster for lazy sequences
* repeat - now implements IReduce
* cycle - implements IReduceInit
* iterate - implements IReduceInit
* range - implements IReduce, specialized case handles common case of all longs
* keys - iterates directly over the keys of a map, without seq or MapEntry allocation
* vals - iterates directly over the vals of a map, without seq or MapEntry allocation
* iterator-seq - creates a chunked sequence when previously it was unchunked
Additionally, hash-maps and hash-sets now provide iterators that walk
the data structure directly rather than via a sequence.
A new interface (IMapIterable) for direct key and val iterators on maps
was added. External data structures can use this interface to provide
direct key and val iterators via keys and vals.
These enhancements are particularly effective when used
in tandem with transducers via transduce, sequence, into, and
eduction.
### 1.7 Printing as data
There have been enhancements in how the REPL prints values without a
print-method, specifically Throwable and the fallthrough Object case.
Both cases now print in a tagged literal data form that can be read
by the reader.
Unhandled objects print with the class, hash code, and toString:
user=> *ns*
#object[clojure.lang.Namespace 0x55aa628 "user"]
Thrown exceptions will still be printed in the normal way by the default
REPL but printing them to a stream will show a different form:
user=> (/ 1 0)
ArithmeticException Divide by zero clojure.lang.Numbers.divide (Numbers.java:158)
user=> (println *e)
#error{:cause Divide by zero,
:via [{:type java.lang.ArithmeticException,
:message Divide by zero,
:at [clojure.lang.Numbers divide Numbers.java 158]}],
:trace
[[clojure.lang.Numbers divide Numbers.java 158]
[clojure.lang.Numbers divide Numbers.java 3808]
[user$eval5 invoke NO_SOURCE_FILE 3]
;; elided ...
]]}
## 2 Enhancements
### 2.1 Error messages
Invalid defrecord results in exception attributed to consuming ns instead of defrecord ns
Report line,column, and source in defmacro errors
Give more specific hint if namespace with "-" not found to check file uses "_"
### 2.2 Documentation strings
Fix typo in gen-class doc-string
Fix typo in filterv example
Fix typo in defmulti docstring
Fix typo in deftype docstring
Fix typo in clojure.main usage
### 2.3 Performance
Improve performance of partial with more unrolling
clojure.core/set should use transients for better performance
Cache unknown multimethod value default dispatch
Reduce compile times by avoiding unnecessary calls to Class.forName()
vec is now faster on almost all inputs
set is now faster on almost all inputs
Fixed reflection call in variadic vector-of constructor
### 2.4 Other enhancements
Improve apropos to show some indication of namespace of symbols found
Hints don't work with #() form of function
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).
Extracted IAtom interface implemented by Atom.
Don't initialize classes when importing them
Class name clash between top-level functions and defn'ed ones
Update to latest test.generative and add dependency on test.check
vec now works with things that only implement Iterable or IReduceInit
set now works with things that only implement Iterable or IReduceInit
PersistentList/creator doesn't handle ArraySeqs correctly
Clean up unused paths in InternalReduce
Add setLineNumber() to LineNumberingPushbackReader
Change test to avoid using hard-coded socket port
Change reduce tests to better catch reduce without init bugs
## 3 Bug Fixes
Reduce broken on some primitive vectors
Equality bug on records created with nested calls to map->record
Unable to set compiler options via system properties except for AOT compilation
NPE when AOTing overrided clojure.core functions
reductions does not check for reduced value
Using def with metadata {:type :anything} throws ClassCastException during printing
Error when calling primitive functions with destructuring in the arg vector
Piping seque into seque can deadlock
<= is incorrect when args include Double/NaN
Make cached string value of Keyword and Symbol transient
clojure.core/bean should implement Iterable
Make refer of Clojure core function not throw exception on reload
LazySeq equals() should not use equiv() logic
into (and other fns that rely on reduce) require only IReduceInit
PersistentVector now directly implements reduce without init
Transient collections should guarantee thread visibility
Some IReduce/IReduceInit implementors don't respect reduced
Clojure resolves to wrong deftype classes when AOT compiling or reloading
Fix intermittent SeqIterator problem by removing use of this as a sentinel
Fix regression from CLJ-1546 that broke vec on MapEntry
Fix regression from CLJ-979 for DynamicClassLoader classloader delegation
Fix error from AOT'ed code defining a var with a clojure.core symbol name
Fix incorrect line number reporting for error locations
Fix incorrect line number reporting for error locations
Fix regression from CLJ-1546 removed PersistentVector.create(List) method
Fix regression from CLJ-1248 (1.6) in reflection warning with literal nil argument