现在来看一下前面译文中碰到的代码:
第一个是nil, 和Java的null值相同,和false一样可以表达条件判断不为true的情况。下面是解释:
nil nil is a possible value of any data type in Clojure. nil has the same value as Java null. The Clojure conditional system is based around nil and false, with nil and false representing the values of logical falsity in conditional tests - anything else is logical truth. In addition, nil is used as the end-of-sequence sentinel value in the sequence protocol.
(ns project1.core) (defn -main "I don't do a whole lot." [& args] (println "Hello, World!" ) (println args) (println (count args)))
user=> (require 'project1.core) nil user=> (project1.core/-main "b") Hello, World! (b) 1 nil解释:
[ ] 方括号是指创建一个vector(数组)
& args指的是数组元素可变
(println args) 打印所有输入参数, args是一个list,包含了所有参数
(count args) 计算参数数目
现在看看如何不使用REPL会话运行程序, 直接输入下面的命令:
lein run -m project1.core "a" Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar Hello, World! (a) 1会自动找到project1.core namespace下面的-main函数并执行。