fbpx
维基百科

Clojure

Clojure/ˈklʒər/[16][17]Lisp编程语言Java平台上的现代、动态函数式方言。[18][19] 与其他Lisp一样,Clojure视代码为数据且拥有一套Lisp系统。[20]Clojure的开发过程目前由社区驱动,[21]其作者里奇·希基则以终身仁慈独裁者的身份监督。[22]

Clojure
编程范型多重编程范型:
設計者里奇·希基
发行时间2007年,​16年前​(2007
目前版本
  • 1.11.1 (2022年4月5日)[8]
型態系統
系统平台
許可證Eclipse公共许可证
文件扩展名
  • .clj
  • .cljs
  • .cljc
  • .edn
網站clojure.org
啟發語言
影響語言

Clojure提倡不可变性与持久数据结构并鼓励程序员显式地管理标识及其状态。[23]对利用不可变值及显式时间进展构造(explicit progression-of-time constructs)进行编程的专注旨在促进更加健壮的(尤其是并发)程序的开发。[24][25][16]Clojure的类型系统是完全动态的,但人们近期也开始探索其基于渐进类型化的实现。[26]

对Clojure的商业支持由Cognitect公司提供。[27] 每年都会在全球范围内举办年度Clojure会议,其中最著名的是Clojure/conj[28]

历史与开发过程

 
里奇·希基,Clojure的创造者

里奇·希基创造了Clojure语言。[18]此前,他开发过类似但基于.NET平台的项目——dotLisp。[29]在那之前,他还尝试了三次在Lisp与Java之间提供互操作:Common Lisp的Java外语接口[30]、Lisp的外语对象接口[31]以及Lisp友好的Java Servlet接口[32]

在公开发布之前,里奇·希基花了大约两年半的时间开发Clojure。他在没有外部资金的情况下,将其大部分时间都专门投入到了Clojure的工作上。开发快要完成,里奇·希基向Common Lisp社区里的一些朋友发布电子邮件,宣布他完成开发了Clojure。

Clojure的开发过程在Clojure JIRA项目网页由社区驱动并管理。[21][33]该网站可用于提交问题报告。一般的开发讨论是在Clojure谷歌网上论坛上进行的。[34] 任何人都可以提交错误报告和想法,而贡献补丁前则需要先签署Clojure贡献者协议。[35] JIRA错误报告由一组筛选者处理,最终由里奇·希基批准更改。[36]

设计理念

里奇·希基开发Clojure的原因是因为他想要一款适合函数式编程的现代Lisp。该语言既需要与已建立的Java平台共生又需要有适合并发性的设计。[24][25][37][16]

在Clojure中,状态以标识的概念为特征。[23]一系列状态随着时间的推移而产生,就是标识。由于状态是不可变的值,任意数量的工作单位都可以在其上并行实施操作,并发性就成为一道管理状态到状态的变化的问题。因此,Clojure提供了几个可变的引用类型。每个引用类型都有其明确定义的语义用于控制状态之间的跃迁。[23]

语言概述

版本 发布日期 主要功能/改进
2007年10月16日[38] 首次公开发布
1.0 2009年5月4日[39] 首个稳定版
1.1 2009年12月31日[40] 将来
1.2 2010年8月19日[41] 协议
1.3 2011年9月23日[42] 增强对原始类型的支持
1.4 2012年4月15日[43] 读取器字面量
1.5 2013年3月1日[44] 归纳器
1.5.1 2013年3月10日[45] 修复内存泄漏
1.6 2014年3月25[46] Java API、经过改进的哈希算法
1.7 2015年6月30日[47] 变换归纳器、读取器条件表达式
1.8 2016年1月19日[48] 附加的字符串函数、直接连接、套接字服务器
1.9 2017年12月8日[49] 集成spec、命令行工具
1.10 2018年12月17日[50] 经过改进的错误报告、Java兼容性
1.10.1 2019年6月6日[51] 解决Java性能回归问题并改进clojure.main的错误报告
1.10.2 2021年1月26日 (2021-01-26)[52] Java互操作性/兼容性改进和其他重要语言修订
1.10.3 2021年3月4日 (2021-03-04)[53] prepl支持读者条件
1.11.0 2022年3月22日 (2022-03-22)[54] 新的关键字参数调用语法,新的clojure.math名字空间,名字空间别名不用加载,并向clojure.core增加新的帮助函数
當前版本: 1.11.1 2022年4月5日 (2022-04-05)[15] 在类型clojure.lang.Keywordclojure.lang.ArraySeq的对象的二进制序列化中回滚意外的变更。
格式:
舊版本
舊版本,仍被支援
当前版本
最新的预览版
未来版本

Clojure执行于Java平台之上,因此,与Java紧密集成并完全支持从Clojure调用Java代码。[55][16] 与此同时,也可以从Java调用Clojure代码。[56] Leiningen是社区中普遍使用的项目自动化工具。Leiningen为Maven集成提供支持,处理项目包管理和依赖项。Leiningen的配置使用的则是Clojure语法。[57]

与其他大多数Lisp一样,Clojure的语法建立在S-表达式之上。S-表达式在被编译之前先由读取器解析为数据结构。[58][16] 除了列表之外,Clojure的读取器还支持映射、集合及向量等的字面量语法。这些字面量随后会被直接编译成上述数据结构。[58] Clojure是Lisp-1且有一套与其它Lisp不兼容的数据结构,因此,Clojure不支持与Lisp的其它方言之间的代码级兼容性。[20]

作为一门Lisp方言,函数在Clojure中是一等公民。此外,Clojure还支持读取﹣求值﹣输出循环以及一套宏系统。[6] Clojure的Lisp宏系统与Common Lisp的系统极为相似。唯一不同的是,Clojure的重音符(称为语法引用)用名字空间来限定符号。这有助于防止意外的名字捕获,因为Clojure禁止绑定到用名字空间限定的名字(namespace-qualified name)上。如果需要强制捕获宏扩展(capturing macro expansion,)那么就需要显示地完成该过程。Clojure不支持用户定义的读取器宏(reader macro,)但Clojure的读取器支持更具约束力的语法扩展形式。[59] Clojure支持多方法(multimethods。)[60] 对于类似接口的抽象,Clojure提供基于协议[61]的多态性以及基于记录[62]的数据类型系统。 Clojure通过这些设计来提供高性能且动态的多态性以避免所谓的“表达式问题”("expression problem"。)

Clojure支持惰性序列,并鼓励不可变性与持久数据结构(persistent data structure。)Clojure作为一门函数式编程语言将重点放在递归高阶函数上而不是基于副作用循环流程上。Clojure不支持自动尾调用优化,因为JVM还不支持该项优化,[63][64][65]但是,可以用recur关键字显式地执行该项优化。[66] 对于并行并发计算,Clojure提供软件事务内存[67] 响应式代理系统[1]及基于通道的并发编程。[68]

Clojure 1.7引入了读取器条件表达式从而允许在同一名字空间中嵌入Clojure与ClojureScript代码。[47][58] 变换归纳器的加入则提供了另一种组合变换的方法。变换归纳器可以使高阶函数(如,mapfold)更加抽象从而使之独立于其输入数据源。传统地说,这些函数一般被应用于序列上,而变换归纳器允许这些函数被应用于通道上并让用户定义她们自己的变换归纳模型。[69][70][71]

平台

Clojure的主要平台是Java[19][55]但也存在其他目标平台上的实现。其中,最值得关注的是ClojureScript[72](可被编译成ECMAScript 3[73])和ClojureCLR[74].NET平台上的完整移植版,可与其生态系统互操作。)2013年对1,060名受访者进行的Clojure社区调查[75]发现,47%的受访者在使用Clojure的同时也使用ClojureScript。2014年,这一数字增长到了55%,[76]而到了2015年,则达到了66%(根据2,445名受访者)。[77] 人气较高的ClojureScript项目包括React实现,如Reagent[78]、re-frame[79]、Rum[80]及Om[81][82]

人气

随着对函数式编程的兴趣的持续升温,Clojure也越来越多地受到Java平台上的软件开发人员的青睐。该语言也一度成为知名软件开发老将的首选或推荐语言,如Brian Goetz[83][84][85]、Eric Evans[86][87]詹姆斯·高斯林[88]保罗·格雷厄姆[89]及Robert C. Martin(俗称“鲍勃大叔”)[90][91][92][93]等人。

在由Snyk和Java Magazine合作编写的“JVM生态系统报告2018”(据称是“Java开发人员有史以来规模最大的调查”)中,Clojure被评为用于“主要应用程序”的第二大人气编程语言(仅次于Java)。[94]

业内使用Clojure的公司有苹果公司[95][96]Atlassian[97]、Funding Circle[98]Netflix[99]、 Puppet [100]沃尔玛[101]及其他大型软件公司[102]美国国家航空航天局[103]等政府机构。Clojure也一度被用于创意计算,包括视觉艺术、音乐、游戏和诗歌。[104]

美国知名软件咨询公司ThoughtWorks在为其“技术雷达”[105]评估函数式编程语言时表达了他们对Clojure的青睐,称其为“Lisp在JVM上的简单及优雅实现”,并在2012年将其状态提升为“采用”(“ADOPT”)[106]

越来越多的非官方和/或实验性的其他平台实现也验证了该语言的人气:

  • CljPerl[107]:Clojure的Perl实现
  • Clojerl[108]:BEAM(Erlang虚拟机)上的Clojure
  • clojure-py[109]:Clojure的纯Python实现
  • Ferret[110]:可被编译成运行于微控制器的自包含(self-contained)C++11
  • Joker[111]:用Go实现的解释器和linter
  • Las3r[112]:执行于ActionScript虚拟机(Adobe Flash Player平台)的Clojure子集
  • Pixie[113]:受Clojure启发并用RPython实现的Lisp方言
  • Rouge[114]:Clojure基于YARV的Ruby实现

开发工具

Clojure的开发工具在近几年得到了显著的改善。以下是目前最具人气的集成开发环境/编辑器及其Clojure插件。[115]这些工具的结合为Clojure编程提供了出色的支持。

集成开发环境/编辑器及其Clojure插件
集成开发环境/编辑器 Clojure插件
Atom Chlorine[116]
Emacs CIDER[117]
IntelliJ IDEA Clojure-Kit[118]或Cursive[119](提供免费的非商业许可证)
Light Table[120] (不适用)
Vim fireplace.vim[121][122], vim-iced[123]或Conjure(仅限Neovim)[124][125]
Visual Studio Code Calva[126]

除了社区提供的开发工具之外,官方的命令行界面工具[127]也随着Clojure 1.9一起发布并可在GNU/Linux、macOS及Windows上使用。[128]

功能示例

以下示例均可在Clojure REPL中运行(如,使用Clojure命令行界面工具[127]启动的REPL或在REPL.it[129]上提供的在线REPL。)

简单性

由于强调简单性,典型的Clojure程序主要包括函数和简单的数据结构(即列表,向量,映射和集合):

;; 一个典型的Clojure程序的入口 (defn -main ; 函数名 [& args] ; 参数向量 (`&`表示可变参数) (println "Hello, World!")) ; 函数体 

REPL编程

与其他Lisp一样,Clojure的标志性特征之一是基于REPL的交互式编程。[130]在以下示例中,;;表示一行注释的开始,而;; =>则表示输出:

;; 定义一个var (def a 42) ;; => #'user/a ;; 调用名为`+`的函数 (+ a 8) ;; => 50 ;; 调用名为`even?`的函数 (even? a) ;; => true ;; 定义一个函数以返回n除10之余 (defn foo [n] (rem n 10)) ;; => #'user/foo ;; 调用该函数 (foo a) ;; => 2 ;; 打印`rem`的文档字符串(docstring) (doc rem) ;; => ------------------------- clojure.core/rem ([num div]) remainder of dividing numerator by denominator. ;; 打印`rem`的源代码 (source rem) ;; => (defn rem "remainder of dividing numerator by denominator." {:added "1.0" :static true :inline (fn [x y] `(. clojure.lang.Numbers (remainder ~x ~y)))} [num div] (. clojure.lang.Numbers (remainder num div))) 

运行时可用的名字

与Clojure不同,其他语言的编译器会将程序中的名字编译掉使得它们在运行时不可用。而在Clojure中,可以用普通的数据结构对其运行时进行观察:

;; 定义一个var (def a 42) ;; => #'user/a ;; 以映射(map)的形式获取在`user`名字空间中捕获的(interned)所有var (ns-publics 'user) ;; => {a #'user/a} ;; 用`#'`(读取器宏)及其关联的、名字空间限定的符号`user/a`引用该var #'user/a ;; => #'user/a ;; 解引用该var(获取其值) (deref #'user/a) ;; => 42 ;; 定义(并附加文档字符串)一个函数以返回n除10之余 (defn foo "返回`(rem n 10)`" [n] (rem n 10)) ;; => #'user/foo ;; 获取var `#'user/foo`的元数据 (meta #'user/foo) ;; => {:arglists ([n]), :doc "返回`(rem n 10)`", :line 1, :column 1, :file "user.clj", :name foo, :ns #namespace[user]} 

代码即数据(同像性)

与其他Lisp类似,Clojure也具有同像性(又称代码即数据)。从下面的示例中可以看到,用Clojure编写代码从而修改代码本身是非常容易的:

;; 调用一个函数 (代码) (+ 1 1) ;; => 2 ;; 引用该函数调用 ;;(将代码转换成数据,此处为含一组符号的列表) (quote (+ 1 1)) ;; => (+ 1 1) ;; 获取该列表上的首个元素 ;; (视代码为数据并对其进行操作) (first (quote (+ 1 1))) ;; => + ;; 获取该列表上的最后一个元素 ;; (视代码为数据并对其进行操作) (last (quote (+ 1 1))) ;; => 1 ;; 替换原列表上的符号从而获取一个新列表 ;; (视代码为数据并对其进行操作) (map (fn [form] (case form 1 'one + 'plus)) (quote (+ 1 1))) ;; => (plus one one) 

富有表现力的数据变换操作符

穿梭宏(threading macro,如,->->>等)可以在语法上表达一个数据集在一系列变换间穿梭的抽象:

(->> (range 10) (map inc) (filter even?)) ;; => (2 4 6 8 10) 

利用变换归纳器也可以更有效地实现该过程:

(sequence (comp (map inc) (filter even?)) (range 10)) ;; => (2 4 6 8 10) 

标识及其状态的线程安全管理

线程安全的唯一序列号生成器(然而,和许多其他Lisp方言一样,Clojure内部使用其内置的gensym函数):

(def i (atom 0)) (defn generate-unique-id "每次调用会返回一个唯一数字ID。" [] (swap! i inc)) 

java.io.Writer的一个匿名子类(不写任何内容)和一个宏(使用该类来静音其中打印的所有内容):

(def bit-bucket-writer (proxy [java.io.Writer] [] (write [buf] nil) (close [] nil) (flush [] nil))) (defmacro noprint "在对给定的`forms`求值的同时静音所有向`*out*`打印的内容。" [& forms] `(binding [*out* bit-bucket-writer] ~@forms)) (noprint (println "Hello, nobody!")) ;; => nil 

Java互操作

作为其主要设计目标之一,Clojure从一开始就将其宿主平台视为其不可分割的一部分。Clojure与Java之间出色的互操作即得益于此:

;; 调用一个实例方法 (.toUpperCase "apple") ;; => "APPLE" ;; 调用一个静态方法 (System/getProperty "java.vm.version") ;; => "12+33" ;; 创建`java.util.HashMap`的一个实例 ;; 并加入一些键值对(key-value pairs) (doto (java.util.HashMap.) (.put "apple" 1) (.put "banana" 2)) ;; => {"banana" 2, "apple" 1} ;; 创建`java.util.ArrayList`的一个实例 ;; 并用`clojure.core/map`递增(increment)其元素 (def al (doto (java.util.ArrayList.) (.add 1) (.add 2) (.add 3))) (map inc al) ;; => (2 3 4) ;; 利用Java Swing显示一个消息对话框 (javax.swing.JOptionPane/showMessageDialog nil "Hello, World!") ;; => nil 

软件事务内存

10个线程操纵一个共享数据结构,该结构由100个向量组成,而每个向量包含10个(最初是连续的)唯一数字。每个线程随后在两个随机向量中重复选择两个随机位置并交换它们。通过使用Clojure的软件事务内存系统,对向量的所有更改都发生在事务中:

(defn run [nvecs nitems nthreads niters] (let [vec-refs (->> (* nvecs nitems) (range) (into [] (comp (partition-all nitems) (map vec) (map ref)))) swap #(let [v1 (rand-int nvecs) v2 (rand-int nvecs) i1 (rand-int nitems) i2 (rand-int nitems)] (dosync (let [tmp (nth @(vec-refs v1) i1)] (alter (vec-refs v1) assoc i1 (nth @(vec-refs v2) i2)) (alter (vec-refs v2) assoc i2 tmp)))) report #(->> vec-refs (into [] (comp (map deref) (map (fn [v] (prn v) v)) cat (distinct))) (count) (println "Distinct:"))] (report) (->> #(dotimes [_ niters] (swap)) (repeat nthreads) (apply pcalls) (dorun)) (report))) (run 100 10 10 100000) ;; => [0 1 2 3 4 5 6 7 8 9] [10 11 12 13 14 15 16 17 18 19] ... [990 991 992 993 994 995 996 997 998 999] Distinct: 1000 [382 318 466 963 619 22 21 273 45 596] [808 639 804 471 394 904 952 75 289 778] ... [484 216 622 139 651 592 379 228 242 355] Distinct: 1000 nil 

参考文献

  1. ^ 1.0 1.1 Agents and Asynchronous Actions. Clojure.org. [2019-07-07]. (原始内容于2019-07-02). 
  2. ^ Concurrent Programming. Clojure.org. [2019-07-07]. (原始内容于2019-07-02). 
  3. ^ Hickey, Rich; contributors. core.async. GitHub.com. [2019-07-07]. (原始内容于2019-06-16). 
  4. ^ Functional Programming. Clojure.org. [2019-07-07]. (原始内容于2019-07-02). 
  5. ^ Nolen, David; Hickey, Rich; contributors. core.logic. GitHub.com. [2019-07-07]. (原始内容于2019-06-14). 
  6. ^ 6.0 6.1 Macros. Clojure.org. [2019-07-07]. (原始内容于2019-07-02). 
  7. ^ Esterhazy, Paulus. Threading Macros Guide. Clojure.org. [2019-07-07]. (原始内容于2019-07-02). 
  8. ^ Release 1.11.1. 2022年4月5日 [2022年10月3日]. 
  9. ^ Fogus, Michael. Rich Hickey Q&A. CodeQuarterly.com. 2011 [2019-07-08]. (原始内容于2017-01-11). 
  10. ^ Hickey, Rich. Clojure Bookshelf. Amazon.com. [2019-07-07]. (原始内容于2017-10-03). 
  11. ^ Bonnaire-Sergeant, Ambrose. A Practical Optional Type System for Clojure (学位论文). The University of Western Australia. 2012. 
  12. ^ Clojure Programming (PDF). OReilly.com. [2013-04-30]. (原始内容 (PDF)于2015-05-21). 
  13. ^ Baldridge, Timothy. Pixie. PixieLang.org. [2019-07-07]. (原始内容于2019-07-06). 
  14. ^ Ramachandra, Ramkumar. Rhine. GitHub.org. [2019-07-07]. (原始内容于2019-09-24). 
  15. ^ 15.0 15.1 Miller, Alex. Clojure 1.11.1 release. Clojure.org. 2022-04-05 [2022-08-27]. (原始内容于2022-04-25). 
  16. ^ 16.0 16.1 16.2 16.3 16.4 Edwards, Kathryn. The A-Z of Programming Languages: Clojure. Computerworld.com.au. 2009-08-10 [2019-09-11]. (原始内容于2019-08-26). 
  17. ^ Hickey, Rich. meaning and pronunciation of Clojure. Google.com. 2009-01-05. 
  18. ^ 18.0 18.1 Krill, Paul. Clojure inventor Hickey now aims for Android. InfoWorld.com. 2012-03-22 [2019-07-08]. (原始内容于2019-07-08). 
  19. ^ 19.0 19.1 . Clojure.org. [2019-07-07]. (原始内容存档于2019-07-03). 
  20. ^ 20.0 20.1 Differences with other Lisps. Clojure.org. [2019-07-07]. (原始内容于2019-07-08). 
  21. ^ 21.0 21.1 Development. Clojure.org. [2019-07-07]. (原始内容于2019-07-07). 
  22. ^ Hickey, Rich. Open Source is Not About You. GitHub.com. 2018-11-26 [2019-07-08]. (原始内容于2019-05-26). 
  23. ^ 23.0 23.1 23.2 Values and Change: Clojure’s approach to Identity and State. Clojure.org. [2019-07-07]. (原始内容于2016-01-02). 
  24. ^ 24.0 24.1 Hickey, Rich. Rationale. Clojure.org. [2019-07-07]. (原始内容于2016-01-04). 
  25. ^ 25.0 25.1 Torre, Charles. Expert to Expert: Rich Hickey and Brian Beckman – Inside Clojure. MSDN.com. 2009-10-06 [2018-11-01]. (原始内容于2018-11-03). 
  26. ^ core.typed. GitHub.com. [2019-07-07]. (原始内容于2018-10-09). 
  27. ^ Investing in A Better Way. Cognitect.com. [2019-07-07]. (原始内容于2019-07-05). 
  28. ^ Clojure/conj. Clojure-Conj.org. [2019-07-07]. (原始内容于2015-09-13). 
  29. ^ Hickey, Rich. [ANN] dotLisp – a Lisp dialect for .Net. Google.com. 2002-10-16 [2018-11-03]. (原始内容存档于2011-01-22). 
  30. ^ Hickey, Rich. jfli. SourceForge.net. 2013-04-15 [2018-11-03]. (原始内容于2018-11-03). 
  31. ^ Hickey, Rich. foil - Foreign Object Interface for Lisp. SourceForge.net. 2013-04-03 [2018-11-03]. (原始内容于2018-11-03). 
  32. ^ Hickey, Rich. Lisplets. SourceForge.net. 2013-03-07 [2018-11-03]. (原始内容于2018-11-03). 
  33. ^ Clojure. Atlassian.net. [2019-07-07]. (原始内容于2019-06-23). 
  34. ^ Clojure. Google.com. [2019-07-07]. (原始内容存档于2011-01-22). 
  35. ^ . Clojure.org. [2019-07-07]. (原始内容存档于2019-07-02). 
  36. ^ Workflow. Clojure.org. [2019-07-07]. (原始内容于2019-07-02). 
  37. ^ Elmendorf, Dirk. Economy Size Geek – Interview with Rich Hickey, Creator of Clojure. LinuxJournal.com. 2010-04-01 [2018-11-03]. (原始内容于2018-11-03). 
  38. ^ Hickey, Rich. . BlogSpot.com. 2007-10-16 [2018-11-04]. (原始内容存档于2018-11-04). 
  39. ^ Hickey, Rich. . BlogSpot.com. 2009-05-04 [2018-11-04]. (原始内容存档于2018-11-04). 
  40. ^ Hickey, Rich. . BlogSpot.com. 2009-12-31 [2018-11-04]. (原始内容存档于2018-11-04). 
  41. ^ Hickey, Rich. Clojure 1.2 Release. Google.com. 2010-08-19 [2018-11-03]. (原始内容存档于2011-01-22). 
  42. ^ Redinger, Christopher. [ANN] Clojure 1.3 Released. Google.com. 2011-09-23 [2018-11-03]. (原始内容存档于2011-01-22). 
  43. ^ Dipert, Alan. [ANN] Clojure 1.4 Released. Google.com. 2012-04-17 [2018-11-03]. (原始内容存档于2011-01-22). 
  44. ^ Halloway, Stuart. ANN: Clojure 1.5. Google.com. 2013-03-01 [2018-11-03]. (原始内容存档于2011-01-22). 
  45. ^ Halloway, Stuart. Clojure 1.5.1. Google.com. 2013-03-10 [2018-11-03]. (原始内容存档于2011-01-22). 
  46. ^ Miller, Alex. [ANN] Clojure 1.6. Google.com. 2014-03-25 [2018-11-03]. (原始内容存档于2011-01-22). 
  47. ^ 47.0 47.1 Miller, Alex. . Clojure.org. 2015-06-30 [2019-07-08]. (原始内容存档于2019-07-05). 
  48. ^ Miller, Alex. . Clojure.org. 2016-01-19 [2019-07-08]. (原始内容存档于2019-07-05). 
  49. ^ Miller, Alex. . Clojure.org. 2017-12-08 [2019-07-08]. (原始内容存档于2019-07-05). 
  50. ^ Miller, Alex. . Clojure.org. 2018-12-17 [2018-12-17]. (原始内容存档于2018-12-17). 
  51. ^ Miller, Alex. . Clojure.org. 2019-06-06 [2019-06-08]. (原始内容存档于2019-06-07). 
  52. ^ Miller, Alex. . Clojure.org. 2021-01-26 [2022-01-08]. (原始内容存档于2022-05-07). 
  53. ^ Miller, Alex. . Clojure.org. 2021-03-04 [2022-01-08]. (原始内容存档于2022-04-18). 
  54. ^ Miller, Alex. Clojure 1.11.0 release. Clojure.org. 2022-03-22 [2022-08-27]. (原始内容于2022-08-27). 
  55. ^ 55.0 55.1 Hosted on the JVM. Clojure.org. [2019-07-07]. (原始内容于2019-07-02). 
  56. ^ Java Interop. Clojure.org. [2019-07-07]. (原始内容于2019-07-02). 
  57. ^ Hagelberg, Phil; contributors. Leiningen. Leiningen.org. [2019-07-07]. (原始内容于2019-07-16). 
  58. ^ 58.0 58.1 58.2 The Reader. Clojure.org. [2019-07-07]. (原始内容于2019-07-02). 
  59. ^ Hickey, Rich. edn. GitHub.com. [2019-07-07]. (原始内容于2019-03-02). 
  60. ^ Multimethods and Hierarchies. Clojure.org. [2019-07-07]. (原始内容于2019-07-02). 
  61. ^ Protocols. Clojure.org. [2019-07-07]. (原始内容于2019-07-02). 
  62. ^ Datatypes: deftype, defrecord and reify. Clojure.org. [2019-07-07]. (原始内容于2019-07-02). 
  63. ^ Goetz, Brian. Stewardship: the Sobering Parts. YouTube.com. 2014-11-20 [2018-11-04]. (原始内容于2016-12-19). 
  64. ^ Rose, John. tail calls in the VM. Oracle.com. 2007-07-12 [2018-11-04]. (原始内容于2018-11-04). 
  65. ^ Rose, John. Some languages need to be able to perform tail calls. Java.net. 2009-02-11 [2018-11-04]. (原始内容于2018-11-04). 
  66. ^ Special Forms. Clojure.org. [2019-07-07]. (原始内容于2019-07-02). 
  67. ^ Refs and Transactions. Clojure.org. [2019-07-07]. (原始内容于2016-01-09). 
  68. ^ Hickey, Rich. Clojure core.async Channels. Clojure.org. 2013-06-28 [2019-07-08]. (原始内容于2019-07-05). 
  69. ^ Hickey, Rich. Transducers. YouTube.com. 2014-09-17 [2018-11-04]. (原始内容于2018-10-01). 
  70. ^ Hickey, Rich. Transducers are Coming. Cognitect.com. 2014-08-06 [2019-07-08]. (原始内容于2019-07-07). 
  71. ^ Hickey, Rich. Inside Transducers. YouTube.com. 2014-11-20 [2018-11-04]. (原始内容于2018-12-07). 
  72. ^ ClojureScript. ClojureScript.org. [2019-07-06]. (原始内容于2019-07-01). 
  73. ^ ClojureScript – FAQ (for JavaScript developers). ClojureScript.org. [2018-02-04]. (原始内容于2018-02-05). 
  74. ^ ClojureCLR. GitHub.com. [2012-06-28]. (原始内容于2013-08-25). 
  75. ^ Emerick, Chas. Results of the 2013 State of Clojure & ClojureScript survey. CEmerick.com. 2013-11-18 [2018-11-04]. (原始内容于2018-10-29). 
  76. ^ State of Clojure 2014 Survey Results. WuFoo.com. [2015-09-17]. (原始内容于2015-10-19). 
  77. ^ Gehtland, Justin. State of Clojure 2015 Survey Results. Cognitect.com. 2016-01-28 [2018-11-04]. (原始内容于2018-11-04). 
  78. ^ Reagent. GitHub.io. [2019-07-06]. (原始内容于2019-07-18). 
  79. ^ re-frame. GitHub.com. [2019-07-06]. (原始内容于2019-07-12). 
  80. ^ Prokopov, Nikita. Rum. GitHub.com. [2019-07-06]. (原始内容于2019-12-22). 
  81. ^ Nolen, David. Om. GitHub.com. [2019-07-06]. (原始内容于2019-06-19). 
  82. ^ Coupland, Tom. Om: Enhancing Facebook's React with Immutability. InfoQ.com. 2014-01-17 [2019-07-08]. (原始内容于2019-07-06). 
  83. ^ Goetz, Brian. Brian Goetz' favorite non-Java JVM language (Part 1 of 3). Twitch.tv. 2020-05-24 [2020-08-07]. (原始内容于2020-07-28). 
  84. ^ Goetz, Brian. Brian Goetz' favorite non-Java JVM language (Part 2 of 3). Twitch.tv. 2020-05-24 [2020-08-07]. (原始内容于2020-07-28). 
  85. ^ Goetz, Brian. Brian Goetz' favorite non-Java JVM language (Part 3 of 3). Twitch.tv. 2020-05-24 [2020-08-07]. (原始内容于2020-07-28). 
  86. ^ Evans, Eric. Modelling Time - Eric Evans - Domain-Driven Design Europe 2018. YouTube.com. 2018-08-14 [2019-11-10]. (原始内容于2019-09-30). 
  87. ^ Evans, Eric. . Twitter.com. 2014-11-21 [2019-11-10]. (原始内容存档于2021-06-11). 
  88. ^ James Gostling meetup with London Java Community. YouTube.com. 2016-10-11 [2019-06-08]. (原始内容于2019-09-24). 
  89. ^ Graham, Paul. Paul Graham on Twitter. Twitter.com. 2016-05-06 [2019-06-08]. (原始内容于2020-01-27). 
  90. ^ Martin, Robert. Why Clojure?. CleanCoder.com. 2019-08-22 [2019-08-23]. (原始内容于2019-08-23). 
  91. ^ Martin, Robert. Unble Bob Martin on Twitter. Twitter.com. 2018-11-29 [2019-06-08]. (原始内容于2019-09-24). 
  92. ^ Martin, Robert. Introduction To Functional Programming. CleanCoders.com. 2018-08 [2019-07-08]. (原始内容于2019-07-08). 
  93. ^ Martin, Robert. Pragmatic Functional Programming. CleanCoder.com. 2017-07-11 [2019-07-08]. (原始内容于2019-07-08). 
  94. ^ Maple, Simon; Binstock, Andrew. . Snyk.io. 2018-10-17 [2019-06-08]. (原始内容存档于2019-06-08). 
  95. ^ Liutikov, Roman. Roman Liutikov on Twitter. Twitter.com. 2017-12-17 [2018-11-02]. (原始内容于2019-02-15). 
  96. ^ Jobs at Apple. Apple.com. [2019-07-06]. (原始内容于2018-12-08). 
  97. ^ Borges, Leonardo. Realtime Collaboration with Clojure. YouTube.com. 2015-07-07 [2019-06-08]. (原始内容于2018-09-06). 
  98. ^ Pither, Jon. Clojure in London: Funding Circle – Lending some Clojure. JUXT.pro. 2016-10-04 [2018-11-02]. (原始内容于2018-12-08). 
  99. ^ Williams, Alex. The New Stack Makers: Adrian Cockcroft on Sun, Netflix, Clojure, Go, Docker and More. TheNewStack.io. 2014-08-03 [2019-06-08]. (原始内容于2019-06-08). 
  100. ^ Price, Chris. A New Era of Application Services at Puppet Labs. Puppet.com. 2014-04-11 [2020-08-06]. (原始内容于2019-09-03). 
  101. ^ Phillips, Marc. Walmart Runs Clojure at Scale. Cognitect.com. 2015-07-14 [2018-11-03]. (原始内容于2018-11-03). 
  102. ^ Success Stories. Clojure.org. [2018-10-27]. (原始内容于2018-10-28). 
  103. ^ Common-Metadata-Repository. GitHub.com. [2019-07-06]. (原始内容于2019-03-22). 
  104. ^ Meier, Carin. Creative computing with Clojure. OReilly.com. 2015-05-06 [2018-11-04]. (原始内容于2018-10-29). 
  105. ^ Frequently Asked Questions - Technology Radar - ThoughtWorks. ThoughtWorks.com. [2019-02-10]. (原始内容于2019-02-07). 
  106. ^ Clojure - Technology Radar - ThoughtWorks. ThoughtWorks.com. [2019-02-10]. (原始内容于2019-02-12). 
  107. ^ Hu, Wei. A Lisp on Perl. MetaCPAN.org. [2019-07-06]. (原始内容于2019-06-04). 
  108. ^ Facorro, Juan. Clojerl. GitHub.com. [2019-07-06]. (原始内容于2019-06-20). 
  109. ^ Baldridge, Timothy. clojure-py. GitHub.com. [2019-07-06]. (原始内容于2019-06-20). 
  110. ^ Akkaya, Nurullah. Ferret. Ferret-Lang.org. [2019-07-06]. (原始内容于2019-07-06). 
  111. ^ Bataev, Roman. Joker. Joker-Lang.org. [2019-07-06]. (原始内容于2019-09-24). 
  112. ^ Cannon, Aemon. Laz3r. GitHub.com. [2019-07-06]. (原始内容于2019-05-11). 
  113. ^ Baldridge, Timothy. Pixie. PixieLang.org. [2019-07-06]. (原始内容于2019-07-06). 
  114. ^ Connor, Ashe. Rouge. GitHub.com. [2019-07-06]. (原始内容于2018-06-11). 
  115. ^ Miller, Alex. "State of Clojure 2019" Results. Clojure.org. 2019-02-04 [2019-07-05]. (原始内容于2019-07-05). 
  116. ^ Szabo, Maurício. Chlorine: Socket REPL Client for Clojure and ClojureScript. Atom.io. [2019-07-05]. (原始内容于2019-07-05). 
  117. ^ Batsov, Bozhidar; contributors. CIDER: The Clojure Interactive Development Environment that Rocks. CIDER.mx. [2019-07-05]. (原始内容于2019-06-08). 
  118. ^ Shrago, Greg. Clojure-Kit: Clojure and ClojureScript plugin for IntelliJ-based tools. JetBrains.com. [2019-07-05]. (原始内容于2019-05-31). 
  119. ^ Fleming, Colin. Cursive: Provides full Clojure and ClojureScript language support. JetBrains.com. [2019-07-05]. (原始内容于2019-05-20). 
  120. ^ Light Table: The Next Generation Code Editor. LightTable.com. [2019-07-05]. (原始内容于2019-07-03). 
  121. ^ Pope, Tim. fireplace.vim: Clojure REPL Support. VIM.org. [2019-07-05]. (原始内容于2019-08-22). 
  122. ^ Monroe, Dominic. Clojure and Vim: An overview – It's very possible. JUXT.pro. 2016-12-13 [2019-07-15]. (原始内容于2019-07-14). 
  123. ^ Masashi, Iizuka. vim-iced: Clojure Interactive Development Environment for Vim8/Neovim. GitHub.com. [2020-03-13]. (原始内容于2020-04-10). 
  124. ^ Caldwell, Oliver. Neovim Clojure(Script) tooling over prepl. GitHub.com. [2019-11-09]. (原始内容于2019-11-22). 
  125. ^ Caldwell, Oliver. Getting started with Clojure, Neovim and Conjure in minutes. oli.me.uk. 2019-11-06 [2019-11-10]. (原始内容于2019-11-11). 
  126. ^ Strömberg, Peter. Calva: Clojure & ClojureScript Interactive Programming. VisualStudio.com. [2019-07-05]. (原始内容于2019-08-22). 
  127. ^ 127.0 127.1 Miller, Alex. Deps and CLI Guide. Clojure.org. [2019-07-08]. (原始内容于2019-07-02). 
  128. ^ Miller, Alex. Clojure 1.9. Cognitect.com. 2017-12-08 [2019-07-05]. (原始内容于2019-07-05). 
  129. ^ Online Clojure REPL. REPL.it. [2019-07-08]. (原始内容于2019-07-09). 
  130. ^ Programming at the REPL: Introduction. Clojure.org. [2018-12-04]. (原始内容于2018-12-04). 

延伸阅读

  • Sotnikov, Dmitri, 3rd, Pragmatic Bookshelf, 2020 [2020-08-07], ISBN 978-1-68050-682-2, (原始内容存档于2021-12-17) 
  • Olsen, Russ, Getting Clojure, Pragmatic Bookshelf, 2018 [2020-08-07], ISBN 978-1-68050-300-5, (原始内容于2020-08-07) 
  • Miller, Alex; Halloway, Stuart; Bedra, Aaron, Programming Clojure 3rd, Pragmatic Bookshelf, 2018 [2020-08-07], ISBN 978-1-68050-246-6, (原始内容于2020-08-07) 
  • Rathore, Amit; Avila, Francis, Clojure in Action 2nd, Manning, 2015, ISBN 978-1-61729-152-4 
  • Higginbotham, Daniel, Clojure for the Brave and True, No Starch Press, 2015 [2018-11-05], ISBN 978-1-59327-591-4, (原始内容于2018-11-29) 
  • Gamble, Julian, Clojure Recipes, Pearson Publishing, 2015 [2018-11-05], ISBN 978-0-32192-773-6, (原始内容于2018-11-06) 
  • Vandgrift, Ben; Miller, Alex, Clojure Applied, Pragmatic Bookshelf, 2015 [2020-08-07], ISBN 978-1-68050-074-5, (原始内容于2020-08-07) 
  • Rochester, Eric, Clojure Data Analysis Cookbook 2nd, Packt Publishing, 2015 [2018-11-05], ISBN 978-1-78439-029-7, (原始内容于2018-11-05) 
  • Fogus, Michael; Houser, Chris, The Joy of Clojure 2nd, Manning, 2014 [2018-11-05], ISBN 1-617291-41-2, (原始内容于2018-10-23) 
  • Kelker, Ryan, Clojure for Domain-specific Languages, Packt Publishing, 2013 [2020-08-07], ISBN 978-1-78216-650-4, (原始内容于2020-07-28) 
  • Rochester, Eric, Mastering Clojure Data Analysis, Packt Publishing, 2014 [2018-11-05], ISBN 978-1-78328-413-9, (原始内容于2018-11-05) 
  • Emerick, Chas; Carper, Brian; Grand, Christophe, Clojure Programming, O'Reilly Media, April 19, 2012 [2018-11-05], ISBN 1-4493-9470-1, (原始内容于2019-01-07) 
  • VanderHart, Luke; Sierra, Stuart, Practical Clojure, Apress, June 7, 2010 [2018-11-05], ISBN 978-1-4302-7231-1, (原始内容于2018-11-05) 

外部链接

官方网站  

clojure, 是lisp编程语言在java平台上的现代, 动态及函数式方言, 与其他lisp一样, 视代码为数据且拥有一套lisp宏系统, 的开发过程目前由社区驱动, 其作者里奇, 希基则以终身仁慈独裁者的身份监督, 编程范型多重编程范型, 代理人导向, 并发计算, 函数式, 邏輯編程, 管道编程, 設計者里奇, 希基发行时间2007年, 16年前, 2007, 目前版本1, 2022年4月5日, 型態系統动态类型, 强类型系统平台java, javascript, net許可證eclipse公共许可证文件扩展. Clojure ˈ k l oʊ ʒ er 16 17 是Lisp编程语言在Java平台上的现代 动态及函数式方言 18 19 与其他Lisp一样 Clojure视代码为数据且拥有一套Lisp宏系统 20 Clojure的开发过程目前由社区驱动 21 其作者里奇 希基则以终身仁慈独裁者的身份监督 22 Clojure编程范型多重编程范型 代理人导向 1 并发计算 2 3 函数式 4 邏輯編程 5 宏 6 管道编程 7 設計者里奇 希基发行时间2007年 16年前 2007 目前版本1 11 1 2022年4月5日 8 型態系統动态类型 强类型系统平台Java JavaScript NET許可證Eclipse公共许可证文件扩展名 clj cljs cljc edn網站clojure wbr org啟發語言C C 9 Common Lisp Erlang Haskell Java Mathematica 10 ML Prolog Racket 11 Ruby 12 Scheme影響語言Elixir Hy LFE 英语 LFE programming language Pixie 13 Rhine 14 維基教科書中有關Clojure Programming的文本Clojure提倡不可变性与持久数据结构并鼓励程序员显式地管理标识及其状态 23 对利用不可变值及显式时间进展构造 explicit progression of time constructs 进行编程的专注旨在促进更加健壮的 尤其是并发 程序的开发 24 25 16 Clojure的类型系统是完全动态的 但人们近期也开始探索其基于渐进类型化的实现 26 对Clojure的商业支持由Cognitect公司提供 27 每年都会在全球范围内举办年度Clojure会议 其中最著名的是Clojure conj 28 目录 1 历史与开发过程 2 设计理念 3 语言概述 4 平台 5 人气 6 开发工具 7 功能示例 7 1 简单性 7 2 REPL编程 7 3 运行时可用的名字 7 4 代码即数据 同像性 7 5 富有表现力的数据变换操作符 7 6 标识及其状态的线程安全管理 7 7 宏 7 8 Java互操作 7 9 软件事务内存 8 参考文献 9 延伸阅读 10 外部链接历史与开发过程 编辑 里奇 希基 Clojure的创造者 里奇 希基创造了Clojure语言 18 此前 他开发过类似但基于 NET平台的项目 dotLisp 29 在那之前 他还尝试了三次在Lisp与Java之间提供互操作 Common Lisp的Java外语接口 30 Lisp的外语对象接口 31 以及Lisp友好的Java Servlet接口 32 在公开发布之前 里奇 希基花了大约两年半的时间开发Clojure 他在没有外部资金的情况下 将其大部分时间都专门投入到了Clojure的工作上 开发快要完成 里奇 希基向Common Lisp社区里的一些朋友发布电子邮件 宣布他完成开发了Clojure Clojure的开发过程在Clojure JIRA项目网页由社区驱动并管理 21 33 该网站可用于提交问题报告 一般的开发讨论是在Clojure谷歌网上论坛上进行的 34 任何人都可以提交错误报告和想法 而贡献补丁前则需要先签署Clojure贡献者协议 35 JIRA错误报告由一组筛选者处理 最终由里奇 希基批准更改 36 设计理念 编辑里奇 希基开发Clojure的原因是因为他想要一款适合函数式编程的现代Lisp 该语言既需要与已建立的Java平台共生又需要有适合并发性的设计 24 25 37 16 在Clojure中 状态以标识的概念为特征 23 一系列状态随着时间的推移而产生 就是标识 由于状态是不可变的值 任意数量的工作单位都可以在其上并行实施操作 并发性就成为一道管理状态到状态的变化的问题 因此 Clojure提供了几个可变的引用类型 每个引用类型都有其明确定义的语义用于控制状态之间的跃迁 23 语言概述 编辑版本 发布日期 主要功能 改进2007年10月16日 38 首次公开发布1 0 2009年5月4日 39 首个稳定版1 1 2009年12月31日 40 将来1 2 2010年8月19日 41 协议1 3 2011年9月23日 42 增强对原始类型的支持1 4 2012年4月15日 43 读取器字面量1 5 2013年3月1日 44 归纳器1 5 1 2013年3月10日 45 修复内存泄漏1 6 2014年3月25 46 Java API 经过改进的哈希算法1 7 2015年6月30日 47 变换归纳器 读取器条件表达式1 8 2016年1月19日 48 附加的字符串函数 直接连接 套接字服务器1 9 2017年12月8日 49 集成spec 命令行工具1 10 2018年12月17日 50 经过改进的错误报告 Java兼容性1 10 1 2019年6月6日 51 解决Java性能回归问题并改进clojure main的错误报告1 10 2 2021年1月26日 2021 01 26 52 Java互操作性 兼容性改进和其他重要语言修订1 10 3 2021年3月4日 2021 03 04 53 prepl支持读者条件1 11 0 2022年3月22日 2022 03 22 54 新的关键字参数调用语法 新的clojure math名字空间 名字空间别名不用加载 并向clojure core增加新的帮助函数當前版本 1 11 1 2022年4月5日 2022 04 05 15 在类型clojure lang Keyword和clojure lang ArraySeq的对象的二进制序列化中回滚意外的变更 格式 舊版本舊版本 仍被支援当前版本最新的预览版未来版本Clojure执行于Java平台之上 因此 与Java紧密集成并完全支持从Clojure调用Java代码 55 16 与此同时 也可以从Java调用Clojure代码 56 Leiningen是社区中普遍使用的项目自动化工具 Leiningen为Maven集成提供支持 处理项目包管理和依赖项 Leiningen的配置使用的则是Clojure语法 57 与其他大多数Lisp一样 Clojure的语法建立在S 表达式之上 S 表达式在被编译之前先由读取器解析为数据结构 58 16 除了列表之外 Clojure的读取器还支持映射 集合及向量等的字面量语法 这些字面量随后会被直接编译成上述数据结构 58 Clojure是Lisp 1且有一套与其它Lisp不兼容的数据结构 因此 Clojure不支持与Lisp的其它方言之间的代码级兼容性 20 作为一门Lisp方言 函数在Clojure中是一等公民 此外 Clojure还支持读取 求值 输出循环以及一套宏系统 6 Clojure的Lisp宏系统与Common Lisp的系统极为相似 唯一不同的是 Clojure的重音符 称为语法引用 用名字空间来限定符号 这有助于防止意外的名字捕获 因为Clojure禁止绑定到用名字空间限定的名字 namespace qualified name 上 如果需要强制捕获宏扩展 capturing macro expansion 那么就需要显示地完成该过程 Clojure不支持用户定义的读取器宏 reader macro 但Clojure的读取器支持更具约束力的语法扩展形式 59 Clojure支持多方法 multimethods 60 对于类似接口的抽象 Clojure提供基于协议 61 的多态性以及基于记录 62 的数据类型系统 Clojure通过这些设计来提供高性能且动态的多态性以避免所谓的 表达式问题 expression problem Clojure支持惰性序列 并鼓励不可变性与持久数据结构 persistent data structure Clojure作为一门函数式编程语言将重点放在递归与高阶函数上而不是基于副作用的循环流程上 Clojure不支持自动尾调用优化 因为JVM还不支持该项优化 63 64 65 但是 可以用recur关键字显式地执行该项优化 66 对于并行与并发计算 Clojure提供软件事务内存 67 响应式代理系统 1 及基于通道的并发编程 68 Clojure 1 7引入了读取器条件表达式从而允许在同一名字空间中嵌入Clojure与ClojureScript代码 47 58 变换归纳器的加入则提供了另一种组合变换的方法 变换归纳器可以使高阶函数 如 map和fold 更加抽象从而使之独立于其输入数据源 传统地说 这些函数一般被应用于序列上 而变换归纳器允许这些函数被应用于通道上并让用户定义她们自己的变换归纳模型 69 70 71 平台 编辑Clojure的主要平台是Java 19 55 但也存在其他目标平台上的实现 其中 最值得关注的是ClojureScript 72 可被编译成ECMAScript 3 73 和ClojureCLR 74 NET平台上的完整移植版 可与其生态系统互操作 2013年对1 060名受访者进行的Clojure社区调查 75 发现 47 的受访者在使用Clojure的同时也使用ClojureScript 2014年 这一数字增长到了55 76 而到了2015年 则达到了66 根据2 445名受访者 77 人气较高的ClojureScript项目包括React实现 如Reagent 78 re frame 79 Rum 80 及Om 81 82 人气 编辑随着对函数式编程的兴趣的持续升温 Clojure也越来越多地受到Java平台上的软件开发人员的青睐 该语言也一度成为知名软件开发老将的首选或推荐语言 如Brian Goetz 83 84 85 Eric Evans 86 87 詹姆斯 高斯林 88 保罗 格雷厄姆 89 及Robert C Martin 俗称 鲍勃大叔 90 91 92 93 等人 在由Snyk和Java Magazine合作编写的 JVM生态系统报告2018 据称是 Java开发人员有史以来规模最大的调查 中 Clojure被评为用于 主要应用程序 的第二大人气编程语言 仅次于Java 94 业内使用Clojure的公司有苹果公司 95 96 Atlassian 97 Funding Circle 98 Netflix 99 Puppet 100 沃尔玛 101 及其他大型软件公司 102 与美国国家航空航天局 103 等政府机构 Clojure也一度被用于创意计算 包括视觉艺术 音乐 游戏和诗歌 104 美国知名软件咨询公司ThoughtWorks在为其 技术雷达 105 评估函数式编程语言时表达了他们对Clojure的青睐 称其为 Lisp在JVM上的简单及优雅实现 并在2012年将其状态提升为 采用 ADOPT 106 越来越多的非官方和 或实验性的其他平台实现也验证了该语言的人气 CljPerl 107 Clojure的Perl实现 Clojerl 108 BEAM Erlang虚拟机 上的Clojure clojure py 109 Clojure的纯Python实现 Ferret 110 可被编译成运行于微控制器的自包含 self contained C 11 Joker 111 用Go实现的解释器和linter Las3r 112 执行于ActionScript虚拟机 Adobe Flash Player平台 的Clojure子集 Pixie 113 受Clojure启发并用RPython实现的Lisp方言 Rouge 114 Clojure基于YARV的Ruby实现开发工具 编辑Clojure的开发工具在近几年得到了显著的改善 以下是目前最具人气的集成开发环境 编辑器及其Clojure插件 115 这些工具的结合为Clojure编程提供了出色的支持 集成开发环境 编辑器及其Clojure插件 集成开发环境 编辑器 Clojure插件Atom Chlorine 116 Emacs CIDER 117 IntelliJ IDEA Clojure Kit 118 或Cursive 119 提供免费的非商业许可证 Light Table 120 不适用 Vim fireplace vim 121 122 vim iced 123 或Conjure 仅限Neovim 124 125 Visual Studio Code Calva 126 除了社区提供的开发工具之外 官方的命令行界面工具 127 也随着Clojure 1 9一起发布并可在GNU Linux macOS及Windows上使用 128 功能示例 编辑以下示例均可在Clojure REPL中运行 如 使用Clojure命令行界面工具 127 启动的REPL或在REPL it 129 上提供的在线REPL 简单性 编辑 由于强调简单性 典型的Clojure程序主要包括函数和简单的数据结构 即列表 向量 映射和集合 一个典型的Clojure程序的入口 defn main 函数名 amp args 参数向量 amp 表示可变参数 println Hello World 函数体 REPL编程 编辑 与其他Lisp一样 Clojure的标志性特征之一是基于REPL的交互式编程 130 在以下示例中 表示一行注释的开始 而 gt 则表示输出 定义一个var def a 42 gt user a 调用名为 的函数 a 8 gt 50 调用名为 even 的函数 even a gt true 定义一个函数以返回n除10之余 defn foo n rem n 10 gt user foo 调用该函数 foo a gt 2 打印 rem 的文档字符串 docstring doc rem gt clojure core rem num div remainder of dividing numerator by denominator 打印 rem 的源代码 source rem gt defn rem remainder of dividing numerator by denominator added 1 0 static true inline fn x y clojure lang Numbers remainder x y num div clojure lang Numbers remainder num div 运行时可用的名字 编辑 与Clojure不同 其他语言的编译器会将程序中的名字编译掉使得它们在运行时不可用 而在Clojure中 可以用普通的数据结构对其运行时进行观察 定义一个var def a 42 gt user a 以映射 map 的形式获取在 user 名字空间中捕获的 interned 所有var ns publics user gt a user a 用 读取器宏 及其关联的 名字空间限定的符号 user a 引用该var user a gt user a 解引用该var 获取其值 deref user a gt 42 定义 并附加文档字符串 一个函数以返回n除10之余 defn foo 返回 rem n 10 n rem n 10 gt user foo 获取var user foo 的元数据 meta user foo gt arglists n doc 返回 rem n 10 line 1 column 1 file user clj name foo ns namespace user 代码即数据 同像性 编辑 与其他Lisp类似 Clojure也具有同像性 又称代码即数据 从下面的示例中可以看到 用Clojure编写代码从而修改代码本身是非常容易的 调用一个函数 代码 1 1 gt 2 引用该函数调用 将代码转换成数据 此处为含一组符号的列表 quote 1 1 gt 1 1 获取该列表上的首个元素 视代码为数据并对其进行操作 first quote 1 1 gt 获取该列表上的最后一个元素 视代码为数据并对其进行操作 last quote 1 1 gt 1 替换原列表上的符号从而获取一个新列表 视代码为数据并对其进行操作 map fn form case form 1 one plus quote 1 1 gt plus one one 富有表现力的数据变换操作符 编辑 穿梭宏 threading macro 如 gt gt gt 等 可以在语法上表达一个数据集在一系列变换间穿梭的抽象 gt gt range 10 map inc filter even gt 2 4 6 8 10 利用变换归纳器也可以更有效地实现该过程 sequence comp map inc filter even range 10 gt 2 4 6 8 10 标识及其状态的线程安全管理 编辑 线程安全的唯一序列号生成器 然而 和许多其他Lisp方言一样 Clojure内部使用其内置的gensym函数 def i atom 0 defn generate unique id 每次调用会返回一个唯一数字ID swap i inc 宏 编辑 java io Writer的一个匿名子类 不写任何内容 和一个宏 使用该类来静音其中打印的所有内容 def bit bucket writer proxy java io Writer write buf nil close nil flush nil defmacro noprint 在对给定的 forms 求值的同时静音所有向 out 打印的内容 amp forms binding out bit bucket writer forms noprint println Hello nobody gt nil Java互操作 编辑 作为其主要设计目标之一 Clojure从一开始就将其宿主平台视为其不可分割的一部分 Clojure与Java之间出色的互操作即得益于此 调用一个实例方法 toUpperCase apple gt APPLE 调用一个静态方法 System getProperty java vm version gt 12 33 创建 java util HashMap 的一个实例 并加入一些键值对 key value pairs doto java util HashMap put apple 1 put banana 2 gt banana 2 apple 1 创建 java util ArrayList 的一个实例 并用 clojure core map 递增 increment 其元素 def al doto java util ArrayList add 1 add 2 add 3 map inc al gt 2 3 4 利用Java Swing显示一个消息对话框 javax swing JOptionPane showMessageDialog nil Hello World gt nil 软件事务内存 编辑 10个线程操纵一个共享数据结构 该结构由100个向量组成 而每个向量包含10个 最初是连续的 唯一数字 每个线程随后在两个随机向量中重复选择两个随机位置并交换它们 通过使用Clojure的软件事务内存系统 对向量的所有更改都发生在事务中 defn run nvecs nitems nthreads niters let vec refs gt gt nvecs nitems range into comp partition all nitems map vec map ref swap let v1 rand int nvecs v2 rand int nvecs i1 rand int nitems i2 rand int nitems dosync let tmp nth vec refs v1 i1 alter vec refs v1 assoc i1 nth vec refs v2 i2 alter vec refs v2 assoc i2 tmp report gt gt vec refs into comp map deref map fn v prn v v cat distinct count println Distinct report gt gt dotimes niters swap repeat nthreads apply pcalls dorun report run 100 10 10 100000 gt 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 990 991 992 993 994 995 996 997 998 999 Distinct 1000 382 318 466 963 619 22 21 273 45 596 808 639 804 471 394 904 952 75 289 778 484 216 622 139 651 592 379 228 242 355 Distinct 1000 nil参考文献 编辑 1 0 1 1 Agents and Asynchronous Actions Clojure org 2019 07 07 原始内容存档于2019 07 02 Concurrent Programming Clojure org 2019 07 07 原始内容存档于2019 07 02 Hickey Rich contributors core async GitHub com 2019 07 07 原始内容存档于2019 06 16 Functional Programming Clojure org 2019 07 07 原始内容存档于2019 07 02 Nolen David Hickey Rich contributors core logic GitHub com 2019 07 07 原始内容存档于2019 06 14 6 0 6 1 Macros Clojure org 2019 07 07 原始内容存档于2019 07 02 Esterhazy Paulus Threading Macros Guide Clojure org 2019 07 07 原始内容存档于2019 07 02 Release 1 11 1 2022年4月5日 2022年10月3日 Fogus Michael Rich Hickey Q amp A CodeQuarterly com 2011 2019 07 08 原始内容存档于2017 01 11 Hickey Rich Clojure Bookshelf Amazon com 2019 07 07 原始内容存档于2017 10 03 Bonnaire Sergeant Ambrose A Practical Optional Type System for Clojure 学位论文 The University of Western Australia 2012 Clojure Programming PDF OReilly com 2013 04 30 原始内容存档 PDF 于2015 05 21 Baldridge Timothy Pixie PixieLang org 2019 07 07 原始内容存档于2019 07 06 Ramachandra Ramkumar Rhine GitHub org 2019 07 07 原始内容存档于2019 09 24 15 0 15 1 Miller Alex Clojure 1 11 1 release Clojure org 2022 04 05 2022 08 27 原始内容存档于2022 04 25 16 0 16 1 16 2 16 3 16 4 Edwards Kathryn The A Z of Programming Languages Clojure Computerworld com au 2009 08 10 2019 09 11 原始内容存档于2019 08 26 Hickey Rich meaning and pronunciation of Clojure Google com 2009 01 05 18 0 18 1 Krill Paul Clojure inventor Hickey now aims for Android InfoWorld com 2012 03 22 2019 07 08 原始内容存档于2019 07 08 19 0 19 1 Clojure Clojure org 2019 07 07 原始内容存档于2019 07 03 20 0 20 1 Differences with other Lisps Clojure org 2019 07 07 原始内容存档于2019 07 08 21 0 21 1 Development Clojure org 2019 07 07 原始内容存档于2019 07 07 Hickey Rich Open Source is Not About You GitHub com 2018 11 26 2019 07 08 原始内容存档于2019 05 26 23 0 23 1 23 2 Values and Change Clojure s approach to Identity and State Clojure org 2019 07 07 原始内容存档于2016 01 02 24 0 24 1 Hickey Rich Rationale Clojure org 2019 07 07 原始内容存档于2016 01 04 25 0 25 1 Torre Charles Expert to Expert Rich Hickey and Brian Beckman Inside Clojure MSDN com 2009 10 06 2018 11 01 原始内容存档于2018 11 03 core typed GitHub com 2019 07 07 原始内容存档于2018 10 09 Investing in A Better Way Cognitect com 2019 07 07 原始内容存档于2019 07 05 Clojure conj Clojure Conj org 2019 07 07 原始内容存档于2015 09 13 Hickey Rich ANN dotLisp a Lisp dialect for Net Google com 2002 10 16 2018 11 03 原始内容存档于2011 01 22 Hickey Rich jfli SourceForge net 2013 04 15 2018 11 03 原始内容存档于2018 11 03 Hickey Rich foil Foreign Object Interface for Lisp SourceForge net 2013 04 03 2018 11 03 原始内容存档于2018 11 03 Hickey Rich Lisplets SourceForge net 2013 03 07 2018 11 03 原始内容存档于2018 11 03 Clojure Atlassian net 2019 07 07 原始内容存档于2019 06 23 Clojure Google com 2019 07 07 原始内容存档于2011 01 22 Contributor Agreement Clojure org 2019 07 07 原始内容存档于2019 07 02 Workflow Clojure org 2019 07 07 原始内容存档于2019 07 02 Elmendorf Dirk Economy Size Geek Interview with Rich Hickey Creator of Clojure LinuxJournal com 2010 04 01 2018 11 03 原始内容存档于2018 11 03 Hickey Rich Clojure is Two BlogSpot com 2007 10 16 2018 11 04 原始内容存档于2018 11 04 Hickey Rich Clojure 1 0 BlogSpot com 2009 05 04 2018 11 04 原始内容存档于2018 11 04 Hickey Rich Clojure 1 1 Release BlogSpot com 2009 12 31 2018 11 04 原始内容存档于2018 11 04 Hickey Rich Clojure 1 2 Release Google com 2010 08 19 2018 11 03 原始内容存档于2011 01 22 Redinger Christopher ANN Clojure 1 3 Released Google com 2011 09 23 2018 11 03 原始内容存档于2011 01 22 Dipert Alan ANN Clojure 1 4 Released Google com 2012 04 17 2018 11 03 原始内容存档于2011 01 22 Halloway Stuart ANN Clojure 1 5 Google com 2013 03 01 2018 11 03 原始内容存档于2011 01 22 Halloway Stuart Clojure 1 5 1 Google com 2013 03 10 2018 11 03 原始内容存档于2011 01 22 Miller Alex ANN Clojure 1 6 Google com 2014 03 25 2018 11 03 原始内容存档于2011 01 22 47 0 47 1 Miller Alex Clojure 1 7 is now available Clojure org 2015 06 30 2019 07 08 原始内容存档于2019 07 05 Miller Alex Clojure 1 8 is now available Clojure org 2016 01 19 2019 07 08 原始内容存档于2019 07 05 Miller Alex Clojure 1 9 is now available Clojure org 2017 12 08 2019 07 08 原始内容存档于2019 07 05 Miller Alex Clojure 1 10 release Clojure org 2018 12 17 2018 12 17 原始内容存档于2018 12 17 Miller Alex Clojure 1 10 1 release Clojure org 2019 06 06 2019 06 08 原始内容存档于2019 06 07 Miller Alex Clojure 1 10 2 release Clojure org 2021 01 26 2022 01 08 原始内容存档于2022 05 07 Miller Alex Clojure 1 10 3 release Clojure org 2021 03 04 2022 01 08 原始内容存档于2022 04 18 Miller Alex Clojure 1 11 0 release Clojure org 2022 03 22 2022 08 27 原始内容存档于2022 08 27 55 0 55 1 Hosted on the JVM Clojure org 2019 07 07 原始内容存档于2019 07 02 Java Interop Clojure org 2019 07 07 原始内容存档于2019 07 02 Hagelberg Phil contributors Leiningen Leiningen org 2019 07 07 原始内容存档于2019 07 16 58 0 58 1 58 2 The Reader Clojure org 2019 07 07 原始内容存档于2019 07 02 Hickey Rich edn GitHub com 2019 07 07 原始内容存档于2019 03 02 Multimethods and Hierarchies Clojure org 2019 07 07 原始内容存档于2019 07 02 Protocols Clojure org 2019 07 07 原始内容存档于2019 07 02 Datatypes deftype defrecord and reify Clojure org 2019 07 07 原始内容存档于2019 07 02 Goetz Brian Stewardship the Sobering Parts YouTube com 2014 11 20 2018 11 04 原始内容存档于2016 12 19 Rose John tail calls in the VM Oracle com 2007 07 12 2018 11 04 原始内容存档于2018 11 04 Rose John Some languages need to be able to perform tail calls Java net 2009 02 11 2018 11 04 原始内容存档于2018 11 04 Special Forms Clojure org 2019 07 07 原始内容存档于2019 07 02 Refs and Transactions Clojure org 2019 07 07 原始内容存档于2016 01 09 Hickey Rich Clojure core async Channels Clojure org 2013 06 28 2019 07 08 原始内容存档于2019 07 05 Hickey Rich Transducers YouTube com 2014 09 17 2018 11 04 原始内容存档于2018 10 01 Hickey Rich Transducers are Coming Cognitect com 2014 08 06 2019 07 08 原始内容存档于2019 07 07 Hickey Rich Inside Transducers YouTube com 2014 11 20 2018 11 04 原始内容存档于2018 12 07 ClojureScript ClojureScript org 2019 07 06 原始内容存档于2019 07 01 ClojureScript FAQ for JavaScript developers ClojureScript org 2018 02 04 原始内容存档于2018 02 05 ClojureCLR GitHub com 2012 06 28 原始内容存档于2013 08 25 Emerick Chas Results of the 2013 State of Clojure amp ClojureScript survey CEmerick com 2013 11 18 2018 11 04 原始内容存档于2018 10 29 State of Clojure 2014 Survey Results WuFoo com 2015 09 17 原始内容存档于2015 10 19 Gehtland Justin State of Clojure 2015 Survey Results Cognitect com 2016 01 28 2018 11 04 原始内容存档于2018 11 04 Reagent GitHub io 2019 07 06 原始内容存档于2019 07 18 re frame GitHub com 2019 07 06 原始内容存档于2019 07 12 Prokopov Nikita Rum GitHub com 2019 07 06 原始内容存档于2019 12 22 Nolen David Om GitHub com 2019 07 06 原始内容存档于2019 06 19 Coupland Tom Om Enhancing Facebook s React with Immutability InfoQ com 2014 01 17 2019 07 08 原始内容存档于2019 07 06 Goetz Brian Brian Goetz favorite non Java JVM language Part 1 of 3 Twitch tv 2020 05 24 2020 08 07 原始内容存档于2020 07 28 Goetz Brian Brian Goetz favorite non Java JVM language Part 2 of 3 Twitch tv 2020 05 24 2020 08 07 原始内容存档于2020 07 28 Goetz Brian Brian Goetz favorite non Java JVM language Part 3 of 3 Twitch tv 2020 05 24 2020 08 07 原始内容存档于2020 07 28 Evans Eric Modelling Time Eric Evans Domain Driven Design Europe 2018 YouTube com 2018 08 14 2019 11 10 原始内容存档于2019 09 30 Evans Eric Eric Evans on Twitter Twitter com 2014 11 21 2019 11 10 原始内容存档于2021 06 11 James Gostling meetup with London Java Community YouTube com 2016 10 11 2019 06 08 原始内容存档于2019 09 24 Graham Paul Paul Graham on Twitter Twitter com 2016 05 06 2019 06 08 原始内容存档于2020 01 27 Martin Robert Why Clojure CleanCoder com 2019 08 22 2019 08 23 原始内容存档于2019 08 23 Martin Robert Unble Bob Martin on Twitter Twitter com 2018 11 29 2019 06 08 原始内容存档于2019 09 24 Martin Robert Introduction To Functional Programming CleanCoders com 2018 08 2019 07 08 原始内容存档于2019 07 08 Martin Robert Pragmatic Functional Programming CleanCoder com 2017 07 11 2019 07 08 原始内容存档于2019 07 08 Maple Simon Binstock Andrew JVM Ecosystem Report 2018 Snyk io 2018 10 17 2019 06 08 原始内容存档于2019 06 08 Liutikov Roman Roman Liutikov on Twitter Twitter com 2017 12 17 2018 11 02 原始内容存档于2019 02 15 Jobs at Apple Apple com 2019 07 06 原始内容存档于2018 12 08 Borges Leonardo Realtime Collaboration with Clojure YouTube com 2015 07 07 2019 06 08 原始内容存档于2018 09 06 Pither Jon Clojure in London Funding Circle Lending some Clojure JUXT pro 2016 10 04 2018 11 02 原始内容存档于2018 12 08 Williams Alex The New Stack Makers Adrian Cockcroft on Sun Netflix Clojure Go Docker and More TheNewStack io 2014 08 03 2019 06 08 原始内容存档于2019 06 08 Price Chris A New Era of Application Services at Puppet Labs Puppet com 2014 04 11 2020 08 06 原始内容存档于2019 09 03 Phillips Marc Walmart Runs Clojure at Scale Cognitect com 2015 07 14 2018 11 03 原始内容存档于2018 11 03 Success Stories Clojure org 2018 10 27 原始内容存档于2018 10 28 Common Metadata Repository GitHub com 2019 07 06 原始内容存档于2019 03 22 Meier Carin Creative computing with Clojure OReilly com 2015 05 06 2018 11 04 原始内容存档于2018 10 29 Frequently Asked Questions Technology Radar ThoughtWorks ThoughtWorks com 2019 02 10 原始内容存档于2019 02 07 Clojure Technology Radar ThoughtWorks ThoughtWorks com 2019 02 10 原始内容存档于2019 02 12 Hu Wei A Lisp on Perl MetaCPAN org 2019 07 06 原始内容存档于2019 06 04 Facorro Juan Clojerl GitHub com 2019 07 06 原始内容存档于2019 06 20 Baldridge Timothy clojure py GitHub com 2019 07 06 原始内容存档于2019 06 20 Akkaya Nurullah Ferret Ferret Lang org 2019 07 06 原始内容存档于2019 07 06 Bataev Roman Joker Joker Lang org 2019 07 06 原始内容存档于2019 09 24 Cannon Aemon Laz3r GitHub com 2019 07 06 原始内容存档于2019 05 11 Baldridge Timothy Pixie PixieLang org 2019 07 06 原始内容存档于2019 07 06 Connor Ashe Rouge GitHub com 2019 07 06 原始内容存档于2018 06 11 Miller Alex State of Clojure 2019 Results Clojure org 2019 02 04 2019 07 05 原始内容存档于2019 07 05 Szabo Mauricio Chlorine Socket REPL Client for Clojure and ClojureScript Atom io 2019 07 05 原始内容存档于2019 07 05 Batsov Bozhidar contributors CIDER The Clojure Interactive Development Environment that Rocks CIDER mx 2019 07 05 原始内容存档于2019 06 08 Shrago Greg Clojure Kit Clojure and ClojureScript plugin for IntelliJ based tools JetBrains com 2019 07 05 原始内容存档于2019 05 31 Fleming Colin Cursive Provides full Clojure and ClojureScript language support JetBrains com 2019 07 05 原始内容存档于2019 05 20 Light Table The Next Generation Code Editor LightTable com 2019 07 05 原始内容存档于2019 07 03 Pope Tim fireplace vim Clojure REPL Support VIM org 2019 07 05 原始内容存档于2019 08 22 Monroe Dominic Clojure and Vim An overview It s very possible JUXT pro 2016 12 13 2019 07 15 原始内容存档于2019 07 14 Masashi Iizuka vim iced Clojure Interactive Development Environment for Vim8 Neovim GitHub com 2020 03 13 原始内容存档于2020 04 10 Caldwell Oliver Neovim Clojure Script tooling over prepl GitHub com 2019 11 09 原始内容存档于2019 11 22 Caldwell Oliver Getting started with Clojure Neovim and Conjure in minutes oli me uk 2019 11 06 2019 11 10 原始内容存档于2019 11 11 Stromberg Peter Calva Clojure amp ClojureScript Interactive Programming VisualStudio com 2019 07 05 原始内容存档于2019 08 22 127 0 127 1 Miller Alex Deps and CLI Guide Clojure org 2019 07 08 原始内容存档于2019 07 02 Miller Alex Clojure 1 9 Cognitect com 2017 12 08 2019 07 05 原始内容存档于2019 07 05 Online Clojure REPL REPL it 2019 07 08 原始内容存档于2019 07 09 Programming at the REPL Introduction Clojure org 2018 12 04 原始内容存档于2018 12 04 延伸阅读 编辑Sotnikov Dmitri Web Development with Clojure 3rd Pragmatic Bookshelf 2020 2020 08 07 ISBN 978 1 68050 682 2 原始内容存档于2021 12 17 Olsen Russ Getting Clojure Pragmatic Bookshelf 2018 2020 08 07 ISBN 978 1 68050 300 5 原始内容存档于2020 08 07 Miller Alex Halloway Stuart Bedra Aaron Programming Clojure 3rd Pragmatic Bookshelf 2018 2020 08 07 ISBN 978 1 68050 246 6 原始内容存档于2020 08 07 Rathore Amit Avila Francis Clojure in Action 2nd Manning 2015 ISBN 978 1 61729 152 4 Higginbotham Daniel Clojure for the Brave and True No Starch Press 2015 2018 11 05 ISBN 978 1 59327 591 4 原始内容存档于2018 11 29 Gamble Julian Clojure Recipes Pearson Publishing 2015 2018 11 05 ISBN 978 0 32192 773 6 原始内容存档于2018 11 06 Vandgrift Ben Miller Alex Clojure Applied Pragmatic Bookshelf 2015 2020 08 07 ISBN 978 1 68050 074 5 原始内容存档于2020 08 07 Rochester Eric Clojure Data Analysis Cookbook 2nd Packt Publishing 2015 2018 11 05 ISBN 978 1 78439 029 7 原始内容存档于2018 11 05 Fogus Michael Houser Chris The Joy of Clojure 2nd Manning 2014 2018 11 05 ISBN 1 617291 41 2 原始内容存档于2018 10 23 Kelker Ryan Clojure for Domain specific Languages Packt Publishing 2013 2020 08 07 ISBN 978 1 78216 650 4 原始内容存档于2020 07 28 Rochester Eric Mastering Clojure Data Analysis Packt Publishing 2014 2018 11 05 ISBN 978 1 78328 413 9 原始内容存档于2018 11 05 Emerick Chas Carper Brian Grand Christophe Clojure Programming O Reilly Media April 19 2012 2018 11 05 ISBN 1 4493 9470 1 原始内容存档于2019 01 07 VanderHart Luke Sierra Stuart Practical Clojure Apress June 7 2010 2018 11 05 ISBN 978 1 4302 7231 1 原始内容存档于2018 11 05 外部链接 编辑官方网站 取自 https zh wikipedia org w index php title Clojure amp oldid 73521986, 维基百科,wiki,书籍,书籍,图书馆,

文章

,阅读,下载,免费,免费下载,mp3,视频,mp4,3gp, jpg,jpeg,gif,png,图片,音乐,歌曲,电影,书籍,游戏,游戏。