并发编程Clojure 1.7版发布

[复制链接]
查看11 | 回复4 | 2014-2-19 11:55:14 | 显示全部楼层 |阅读模式
Clojure是一种LISP风格的语言,运行在JVM上。Clojure的一大特色就是其并发机制,它支持不可变的数据结构(Clojure是来自于可持久化的数据结构)。Clojure还有一个特色是软件事务存储(Software Transactional Memory,STM),其支持用事务代替锁和互斥器来更新共享内存。STM还是一个有争议的技术,还需要更好的证明自己,一个简单的办法就是访问一个JVM上的实现。
Clojure 1.7 发布,该版本最主要的两项特性是 transducers 和 reader conditionals。其中 transducers 可在几种新的和现存的环境中使用:
into - to collect the results of applying a transducer
sequence - to incrementally compute the result of a transducer
transduce - to immediately compute the result of a transducer
eduction - to delay computation and recompute each time
core.async - to apply a transducer while values traverse a channel

回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
1 Compatibility Notes
Please be aware of the following issues when upgrading to Clojure 1.7.
Seqs on Java iterators that return the same mutating object
Seqs are fundamentally incompatible with Java iterators that return the same mutating object on every call to next(). Some Clojure libraries incorrectly rely on calling seq on such iterators.
In 1.7, iterator-seqs are chunked, which will cause many of these incorrect usages to return incorrect results immediately.
The seq and iterator-seq docstrings have been updated to include an explicit warning. Libraries that incorrectly use seq and iterator-seq will need to be fixed before running against 1.7.
CLJ-1669
CLJ-1738
回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
Thread owner check removed on transients
Prior to Clojure 1.7, transients would allow modification only from the thread that created the transient. This check has been removed. It is still a requirement that transients should be updated by only a single thread at a time.
This constraint was relaxed to allow transients to be used in cases where code is multiplexed across multiple threads in a pool (such as go blocks in core.async).
keys/vals require custom map type to implement Iterable
Invoking keys or vals on a custom map type that implements IPersistentMap will now use the Iterable iterator() method instead of accessing entries via the seq of the map. There have been no changes in the type hierarchy (IPersistentMap has always extended Iterable) but former map-like instances may have skipped implementing this method in the past.
CLJ-1602
回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
New and Improved Features
2.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.
Also see: http://clojure.org/transducers
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:
map
mapcat
filter
remove
take
take-while
drop
drop-while
take-nth
replace
partition-by
partition-all
keep
keep-indexed
map-indexed
distinct
interpose
回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
Additionally some new transducer functions have been added:
cat - concatenates the contents of each input
dedupe - 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.
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
conj can be used as a reducing function and will conj to []
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行