[英]Testing Clojure main from REPL
I have defined a -main
function in a :gen-class :main true
namespace in Clojure. 我在Clojure的:gen-class :main true
命名空间中定义了-main
函数。 I am trying to test it from the REPL. 我正在尝试从REPL进行测试。
My main
function looks like this: 我的main
功能如下:
(defn -main [& args]
; ...
)
and I am trying to call it with (ns/-main "-x" "foo")
, (ns/-main "-x foo")
, (ns/-main ["-x" "foo"])
, (ns/-main (into-array String ["-x" "foo"])
, etc., and all give me various errors. 我试图用(ns/-main "-x" "foo")
, (ns/-main "-x foo")
, (ns/-main ["-x" "foo"])
来称呼它(ns/-main (into-array String ["-x" "foo"])
等,所有这些都会给我带来各种错误。
How do I call this function from the REPL and pass in some command line arguments to test it? 如何从REPL调用此函数并传递一些命令行参数对其进行测试?
Thanks. 谢谢。
I tried to reproduce it: 我试图重现它:
(defn -main [& args]
(apply str args)
)
Then called like: 然后称为:
(-main "a" "b" "c")
And it evaluated to: 并且它评估为:
"abc"
As it should.. 正如它应该..
Be sure to check are you using the right namespace identifier, also see if anything weird is happening inside your -main
function, like using a string as a number.. 确保检查是否使用了正确的名称空间标识符,还请查看-main
函数内部是否发生了任何奇怪的事情,例如使用字符串作为数字。
Also, it wouldn't hurt to see your error message on this.. 另外,在此看到您的错误消息也无济于事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.