Clojure的隐藏功能 [英] Hidden features of Clojure
问题描述
Clojure的哪些不太知名但有用的功能是你自己使用的?
我在这些类似问题的答案中发现了一些非常有趣的信息:
- Haskell的隐藏功能
- Python的隐藏功能
-
- Java的隐藏功能
- C的隐藏功能
- < a href =http://stackoverflow.com/questions/161872> Perl的隐藏功能
- Ruby的隐藏功能
Clojure有一个不可变的,持久队列数据类型,PersistentQueue,但它没有(还?)有文字阅读器语法或Clojure包装函数,所以你必须通过Java调用创建一个。队列以良好的性能将(推)后面和前面的弹出。
user> ( - >(clojure.lang.PersistentQueue / EMPTY)
pre>
(conj 1 2 3)
pop)
(2 3)
列出conj在前面,pop从前面。矢量结合在后面和从后面pop。所以队列有时是你需要的。
user> ( - >()
(conj 1 2 3)
pop)
(2 1)
user> ( - > []
(conj 1 2 3)
pop)
[1 2]
Which lesser-known but useful features of Clojure do you find yourselves using? Feel free to share little tricks and idioms, but try to restrict yourselves to Core and Contrib.
I found some really interesting information in answers to these similar questions:
- Hidden features of Haskell
- Hidden features of Python
- Hidden features of Java
- Hidden features of C
- Hidden features of Perl
- Hidden features of Ruby
There are many more "Hidden feature" questions for other languages, so I thought it would be nice to have one for Clojure, too.
Clojure has an immutable, persistent queue datatype, PersistentQueue, but it doesn't (yet?) have literal reader syntax or Clojure wrapper functions, so you have to create one via a Java call. Queues conj (push) onto the rear and pop from the front with good performance.
user> (-> (clojure.lang.PersistentQueue/EMPTY)
(conj 1 2 3)
pop)
(2 3)
Lists conj onto the front and pop from the front. Vectors conj onto the rear and pop from the rear. So queues are sometimes exactly what you need.
user> (-> ()
(conj 1 2 3)
pop)
(2 1)
user> (-> []
(conj 1 2 3)
pop)
[1 2]
这篇关于Clojure的隐藏功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!