如何退出 REPL
我正在尝试退出 REPL。
我使用 (. System exit 0)
或 (System/exit 0)
,但这会导致错误:
Exception in thread "Thread-3" java.lang.RuntimeException: java.lang.IndexOutOfBoundsException
是否还有其他方法退出 REPL?我该如何解决这个错误?
I'm trying to exit the REPL.
I use (. System exit 0)
or (System/exit 0)
, but that causes an error:
Exception in thread "Thread-3" java.lang.RuntimeException: java.lang.IndexOutOfBoundsException
Is there another way to exit the REPL? How I can resolve this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
您可以发送“文件结束”字符。
您只需按 ctrl-d (*nix) 或 ctrl-z (Windows) 即可退出 REPL。
You can send the 'end-of-file' character.
You can just press ctrl-d (*nix) or ctrl-z (Windows) to exit the REPL.
我的答案已经有 10 年历史了,而且人们对它的理解还不够深入(尽管我认为我和最初的提问者有着同样的困惑,所以它还是有效的)。
(System/exit 0)
确实退出整个 JVM - 这可能是您想要的“退出 REPL”,但不一定。 Clojure 及其 REPL 被设计为在多线程环境中运行,您甚至可以将多个 REPL 连接到同一进程。显然,如果您想在一个持续运行的进程中退出 REPL,那么退出 JVM 并不是您想要的。原答案如下:
My answer is now 10 years old and was given a context of less understanding (although I think I shared the same confusion as the original asker so it kind of works).
(System/exit 0)
does indeed exit the whole JVM - that might be what you want "to exit the REPL" but not necessarily. Clojure and it's REPL are designed to run in a multi-threaded environment and you can even have multiple REPLs connected to the same process. Obviously exiting the JVM is not what you want if you want to exit a REPL in an otherwise continuing process.Original answer below:
(System/exit 0) 的问题是它会杀死整个 JVM。真正的问题是如何以编程方式退出当前的 repl,并返回到启动该 repl 的任何函数。
这是一个方便的技巧:
clojure.main/repl 重复调用读取器(默认情况下为 repl-read),一次获取一个表单。向读者提出的论点之一是一个特殊的哨兵对象,当没有更多的表单可供阅读时,读者应该返回该对象。默认读取器 repl-read 仅在 EOF 时返回哨兵值。在 repl-read 提示符处,您无权访问哨兵对象,因此您无法返回它来告诉评估者您已完成表单输入。通过安装您自己的阅读器,您可以检查特定的形式(例如,符号退出),并在读取此形式时返回哨兵对象,从而向评估器表明您已准备好退出 repl,而无需实际杀死整个虚拟机。
The problem with (System/exit 0) is that it kills the whole JVM. The real question is how to programmatically exit just the current repl, and return to whatever function launched that repl.
Here is a convenient hack:
clojure.main/repl repeatedly calls a a reader, by default repl-read, to get one form at a time. One of the arguments to the reader is a special sentinel object that the reader is supposed to return when there are no more forms to be read. The default reader, repl-read, returns the sentinel value only on EOF. At the repl-read prompt, you do not have access to the sentinel object, so you cannot return it to tell the evaluator that you have finished entering forms. By installing your own reader, you can check for a particular form -- e.g., the symbol exit -- and return the sentinel object whenever this form is read, thus indicating to the evaluator that you are ready to exit the repl, without actually killing the entire VM.
我只是想退出我的 REPL 并降落到这里。
当开始在 Clojure REPL 中执行第一步时,这似乎是每个人都会想到的一个问题。当然,我没有阅读启动消息。我的 Clojure 1.7.0 的答案是(退出)或(退出)或 Control-d,如其他回复中所述。
i just wanted to exit my REPL and landed here.
This seems to be a question that comes to everyones mind when starting to do first steps in the Clojure REPL. And of course I did not read the start-up message. The answer for my Clojure 1.7.0 is (exit) or (quit) or Control-d as stated in other replies.
您可以使用以下组合键退出 emacs 中的 Cider REPL:
Cc Cq
You may use the following key combination to exit Cider REPL in emacs:
C-c C-q
如果您安装“lein”,则
exit
或quit
如下所示:If you install "lein" then it's
exit
orquit
like this:在 Linux 上安装 Clojure 1.10.2
On Clojure 1.10.2 installed on Linux
在 Mac 上,使用 CTRL + C 两次,请参阅:
On Mac, use CTRL + C twice, see:
退出repl:
如果您从命令行运行 repl,那么(正如 Sean 提到的)ctrl-d
如果你是从 slime 运行它,那么 Alt-x slime-quit-lisp 应该可以做到。
如果您从 Eclipse 运行它,那么
我不确定是否有一种干净的退出方式,请使用红色小按钮。to exit the repl:
If you're running the repl from the command line then (as Sean mentions) ctrl-d
if you're running it from slime then Alt-x slime-quit-lisp should do it.
if you're running it from eclipse then
i'm not sure there is a clean way to exituse the little red button.今天我得到了答案,这就是我需要的
today I have the answer, this is what I need
在 Windows 中(在 Windows 7 x64 上测试),使用标准命令 shell (cmd.exe),ctrl-Z(后跟 Enter 键)字符似乎是文件结束指示符,它使我脱离了REPL 返回命令提示符。我怀疑这在 Windows PowerShell 中也同样有效,熟悉它的人请测试并确认...
另请注意,这适用于库存 Clojure REPL - 如果您正在运行 Datomic shell(这似乎是一个Java Beanshell 的实例),输入“quit();”...
HTH。
In Windows (tested on Windows 7 x64), using the standard command shell (cmd.exe), the ctrl-Z (followed by the enter key) character appears to be the end-of-file indicator, it dropped me out of the REPL back to the command prompt. I suspect that this will also work equivalently in Windows PowerShell, would someone who is familiar with it please test and confirm...
Note also that this is for the stock Clojure REPL - if you are running the Datomic shell (which appears to be an instance of a Java Beanshell), enter "quit();"...
HTH.