JVM 上的 Lisp 方言 Clojure 1.9

栏目: Lisp · 发布时间: 5年前

内容简介:还是从 OSChina 网站上得知 Clojure 1.9 在  2017 年 12 月发布的,时值这么久才开始真正去了解一下这个新版本。距离上一个版本 1.8 的发布时间(2016 年 1  月), 大概两年才出一个版本,而且总的说来 Clojure 1.9 并没有带来多大惊喜。唯一能带来点喜气的也就是 Clolure 有了自己的命令行工具了,再也无需寄身于在 Clojure 1.9 出来之前,上面的命令会得到如下提示信息

还是从 OSChina 网站上得知 Clojure 1.9 在  2017 年 12 月发布的,时值这么久才开始真正去了解一下这个新版本。距离上一个版本 1.8 的发布时间(2016 年 1  月), 大概两年才出一个版本,而且总的说来 Clojure 1.9 并没有带来多大惊喜。

唯一能带来点喜气的也就是 Clolure 有了自己的命令行 工具 了,再也无需寄身于 Leiningen (一个 Clojure 构建工具,相当于 sbt 之于 Scala) 的篱笆之下了。以 Mac OS 平台为例,以前试图用 brew 来直接安装 clojure 的时候会提示找不到 clojure , 建议安装 leiningen .

$ brew install clojure

在 Clojure 1.9 出来之前,上面的命令会得到如下提示信息

Error: No available formula with the name "clojure"  Clojure isn't really a program but a library managed as part of a  project and Leiningen is the user interface to that library.
To install Clojure you should install Leiningen:  brew install leiningen  and then follow the tutorial:  https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md

所以那时候不得不用

brew install leiningen

安装 leiningen 后,再通过它进入到  Clojure 控制台

JVM 上的 Lisp 方言 Clojure 1.9 现在的 Leiningen 的 repl 还只能支持 Clojure 1.8,但作为项目构建工具应该能和 Clojure 1.9 一同使用。

lein repl 可以用 exit , ctrl + d 退出。当然用 (System/exit 0)(. System exit 0) 代码退出也行。

Clojure 1.9 出来后,我们可以用 brew 安装 Clojure 了

brew install clojure

安装好 Clojure 就能直接运行 clojureclj 命令了

JVM 上的 Lisp 方言 Clojure 1.9 进到 Clojure 的控制台(repl - Read-Eval-Print-Loop) 是那么的干脆。不过不能简单的用 exit 命令退出,退出需要用 ctrl + d , 或者 (System/exit 0) , 或者 (. System exit 0) 来退出 clojure 的  repl。

关于 Clojure 项目的构建工具

其实最想要的是 clojure 能与 Maven 相结合,官方并未出品这样的插件,有一款民间的 clojure-maven-plugin , 能用 Maven 管理 Clojure 项目,不知可靠性如何。

Clojure 官方的推荐的构建工具仍然是 Leiningen Boot , Leiningen 有小试过,不怎么趁手,可能是 Maven 用习惯了。至于 Boot 就完全不同于传统的思维了。

其实 Clojure 也内置有类库依赖管理的功能的,通过 deps.edn 文件来配置,允许用本地库,或从 github, Maven 仓库中下载依赖。详情请见 Clojure 官方文档 Deps and CLI Guide

clojure/clj 并不能称之为一个完备的构建工具,它也只定义最基本的项目布局

hello-world  ├── deps.edn  └── src            └── hello.clj

如果要加上 test 目录, resources 目录必须在 deps.edn 中额外指定。

在项目目录(如 hello-world) 中运行 clj 命令会依据 deps.edn 中的定义下载依赖,也能用 clj -m hello 来运行项目。但它离一个真正的构建工具还很远,不能执行清晰的编译产品代码,编译测试代码,运行测试,打包,布置等操作,更不便于与 CI 的集成。

更多关于 clojure/clj 的命令可运行 clj --help 查看

clj --help
Usage: clojure [dep-opt*] [init-opt*] [main-opt] [arg*]
       clj     [dep-opt*] [init-opt*] [main-opt] [arg*]
 
The clojure script is a runner for Clojure. clj is a wrapper
for interactive repl use. These scripts ultimately construct and
invoke a command-line of the form:
 
java [java-opt*] -cp classpath clojure.main [init-opt*] [main-opt] [arg*]
 
The dep-opts are used to build the java-opts and classpath:
 -Jopt          Pass opt through in java_opts, ex: -J-Xmx512m
 -Ralias...     Concatenated resolve-deps aliases, ex: -R:bench:1.9
 -Calias...     Concatenated make-classpath aliases, ex: -C:dev
         -Sdeps EDN     Deps data to use as the final deps file
 -Spath         Compute classpath and echo to stdout only
 -Srepro        Use only the local deps.edn (ignore other config files)
 -Sforce        Force recomputation of the classpath (don't use the cache)
 -Spom          Generate (or update existing) pom.xml with deps and paths
         -Stree         Print dependency tree
 -Sresolve-tags Resolve git coordinate tags to shas and update deps.edn
 -Sverbose      Print important path info to console
 
init-opt:
 -i, --init path     Load a file or resource
 -e, --eval string   Eval exprs in string; print non-nil values
 
main-opt:
 -m, --main ns-name  Call the -main function from namespace w/args
 -r, --repl          Run a repl
 path                Run a script from a file or resource
 -                   Run a script from standard input
 -h, -?, --help      Print this help message and exit
 
For more info, see:
 https://clojure.org/guides/deps_and_cli
 https://clojure.org/reference/repl_and_main

估计实际要开创一个 Clojure 项目,目前来说首选的构建工具应该还是 Leiningen , 其次是 clojure-maven-plugin (1.8.1 最近更新在 2016 年 5 月)。

最后,在 Clojure 1.9 的 ChangeLog 中提到的其他新的或增强的特性看是否能在实际中用上, 它们包括:

  1. spec
  2. Support for working with maps with qualified keys
  3. New predicates
  4. More support for instants
  5. Other new core functions
  6. Other reader enhancements
  7. Spec syntax checking
  8. Documentation

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Perl语言编程

Perl语言编程

[美] Larry Wall、Tom Christiansen、Jon Orwant / 何伟平 / 中国电力出版社 / 2001-12 / 129.00元

这不仅仅是一本关于Perl的书籍,更是一本独一无二的开发者自己介绍该语言及其文化的书籍。Larry Wall是Perl的开发者,他就这种语言的未来发展方向提出了自己的看法。Tom Christiansen是最早的几个拥护者之一,也是少数几个在错综复杂的中游刃有余的人之一。Jon Orwant是《Perl Journal》的主编,该杂志把Perl社区组合成了一个共同的论坛,以进行Perl新的开发。一起来看看 《Perl语言编程》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具