Clojure环境安装与QuickStart

Clojure环境安装与QuickStart

如果你连环境都不想安装,想直接体验一下Clojure的Lisp感觉,你只要保证你联网,就能做到.

打开http://www.tryclj.com/,这里不需要做任何配置,直接在浏览器上就可以试验 Clojure

项目地址: http://www.tryclj.com/

源码安装

首先要配置好JDK环境,这里不多说.

这个是clojure项目github:
https://github.com/clojure/clojure

让我们直接从源码build打包,然后在java命令行进入Clojure交互运行环境REPL.

执行如下命令:

git clone https://github.com/clojure/clojure
cd clojure
mvn package -Dmaven.test.skip

然后,我们可以在target目录下面,看到clojure-1.9.0-master-SNAPSHOT.jar

在命令行,直接运行java命令行:

java -cp clojure-1.9.0-master-SNAPSHOT.jar clojure.main

我们即可进入Clojure的交互式命令行环境(read-eval-print loop (REPL)):

Clojure 1.9.0-master-SNAPSHOT
user=> (+ 1 2 3)
6
user=> (javax.swing.JOptionPane/showMessageDialog nil "Hello,Clojure!")
nil

输出如下图:

![](螢幕快照 2016-06-28 15.58.33.png)

使用Leiningen

Leiningen是一个Clojure项目管理工具。

Mac上使用homebrew安装

sudo brew install leiningen

如果因为网络原因安装失败,删除掉~/.lein目录后重新执行lein命令即可。
现在可以启动一个REPL会话,更简单:

lein repl

启动成功,控制台输出:

Retrieving org/clojure/tools.nrepl/0.2.12/tools.nrepl-0.2.12.pom from central
Retrieving clojure-complete/clojure-complete/0.2.4/clojure-complete-0.2.4.pom from clojars
Retrieving org/clojure/clojure/1.8.0/clojure-1.8.0.pom from central
Retrieving org/clojure/tools.nrepl/0.2.12/tools.nrepl-0.2.12.jar from central
Retrieving org/clojure/clojure/1.8.0/clojure-1.8.0.jar from central

Jun 28, 2016 4:14:21 PM org.apache.http.impl.execchain.RetryExec execute
資訊: I/O exception (java.net.SocketException) caught when processing request to {s}->https://clojars.org:443: Connection reset
Jun 28, 2016 4:14:21 PM org.apache.http.impl.execchain.RetryExec execute
資訊: Retrying request to {s}->https://clojars.org:443
Retrieving clojure-complete/clojure-complete/0.2.4/clojure-complete-0.2.4.jar from clojars
nREPL server started on port 58986 on host 127.0.0.1 - nrepl://127.0.0.1:58986
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_40-b27
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> (* 1 2 3 4 5 6 7 8 9)
362880
user=> (+ 1 2 3 4 5 6 7 8 9)
45

    原文作者:一个会写诗的程序员
    原文地址: https://www.jianshu.com/p/08666f53d509
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞