我想退出REPL。
我尝试使用(. System exit 0)
或(System/exit 0)
,但会导致错误:
Exception in thread "Thread-3" java.lang.RuntimeException: java.lang.IndexOutOfBoundsException
有没有其他方法退出REPL?我该如何解决这个错误?
我想退出REPL。
我尝试使用(. System exit 0)
或(System/exit 0)
,但会导致错误:
Exception in thread "Thread-3" java.lang.RuntimeException: java.lang.IndexOutOfBoundsException
有没有其他方法退出REPL?我该如何解决这个错误?
lein repl
。 (您应该能够在没有任何项目设置的情况下获得repl)。您的项目代码或结构可能会导致问题。也许您有一些代码在调用主函数之前被评估。 - Alex Stoddard(System/exit 0)的问题在于它会关闭整个JVM。真正的问题是如何以编程方式退出当前的repl,并返回启动该repl的任何函数。
以下是一个方便的解决方法:
(clojure.main/repl
; Exit the repl whenever the user enters "exit" at the prompt.
:read (fn [request-prompt request-exit]
(let [form (clojure.main/repl-read request-prompt request-exit)]
(if (= 'exit form) request-exit form))))
clojure.main/repl 会默认使用 repl-read 函数来反复调用 reader 获取一个表单。reader 的一个参数是一个特殊的哨兵对象,当没有更多的表单需要读取时,reader 应该返回它。repl-read 函数仅在 EOF(文件结尾)时返回哨兵值。在 repl-read 提示符下,您无法访问哨兵对象,因此不能返回哨兵以告诉求值器您已完成输入表单。通过安装自己的 reader,您可以检查特定的表单 - 如符号 exit - 并在读取此表单时返回哨兵对象,从而告诉评估器您准备退出 repl,而不会杀死整个虚拟机。
我只是想退出REPL,结果来到了这里。
当我们开始在Clojure REPL中迈出第一步时,似乎每个人都会有这样的问题。当然,我没有阅读启动消息。对于我的Clojure 1.7.0版本,答案是(exit)或(quit),或者像其他回复中所述,使用Control-d。
nREPL server started on port 49276 on host 127.0.0.1 - nrepl://127.0.0.1:49276
REPL-y 0.3.7, nREPL 0.2.10
Clojure 1.7.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_72-b15
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=> (exit)
Bye for now!
(exit)
失败并出现错误 user=> (exit) Syntax error compiling at (REPL:1:1). Unable to resolve symbol: exit in this context
。我不得不使用 ( (. System exit 0)
来退出。@andreas-guther 我看到你的代码中有头部 nREPL server
,那么版本 1.7 及以下是否可以直接使用 exit
? - Abdurrahman Adebiyi在emacs中退出Cider REPL,你可以使用以下按键组合:C-c C-q
exit
或quit
命令退出:$ lein repl
...
user=>exit
Bye for now!
在 Linux 上安装 Clojure 1.10.2
(. System exit 0)
今天我有了答案,这就是我需要的。
(import ('java.lang.management ManagementFactory)
(use 'clojure.contrib.shell)
(defn process-pid [] (let [m-name (.getName (ManagementFactory/getRuntimeMXBean))] (first (.split m-name "@"))))
(defn exit (sh "kill" (process-pid))
退出repl:
如果您正在从命令行运行repl,则(如Sean所述)使用ctrl-d
如果您正在从slime运行它,则Alt-x slime-quit-lisp应该可以。
如果您正在从eclipse运行它,则我不确定是否有干净的退出方式请使用小红按钮。
java -jar clojure.jar
清理工作在 Clojure 1.11.0-master-SNAPSHOT 上是有效的。我猜在 Linux 版本或 Mac 的 brew 版本中需要使用 (exit) 以正常工作。 - Abdurrahman Adebiyi