如何将 Clojure REPL 的内容转储到文件中?
所以我一直在研究 Clojure 教程,到目前为止它非常有趣。不幸的是,每次我关闭 REPL 时,我都会丢失在上一个会话中创建的所有 defn
和 def
。
那么,为了将来节省时间,是否可以让 Clojure REPL 将我输入的所有内容保存到文件中,以便我可以找出未来使用所需的内容?
So I have been working on a Clojure tutorial and it's pretty fun so far. Unfortunately, every time I close my REPL out, I lose all of the defn
and def
that I created in the previous session.
So, to save time in the future, is it possible to have the Clojure REPL save everything I've typed to a file so I can dig out what I need for future uses?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为大多数人的工作方式是使用 IDE 将代码片段发送到 REPL,而不是在 REPL 中进行大量直接黑客攻击。这样您就可以更好地了解程序的当前状态。
I think most people work by using their IDE to send fragments of code to the REPL, rather than doing a lot of direct hacking in the REPL. This way you have a better idea of the current state of the program.
如果您使用 Emacs 和 SLIME,您可以将 REPL 缓冲区保存到文件中,就像保存任何其他缓冲区一样。
If you use Emacs and SLIME, you can save the REPL buffer to a file just like saving any other buffer.
如果您使用的是类 Unix 操作系统,您可以使用 rlwrap 启动 REPL。这将使您可以使用 Ctrl-R 以简单的方式访问历史记录中的命令,并存储历史记录本身。
您只需安装 rlwrap 并将其添加到启动 REPL 的行,例如 rlwrap lein repl
If you are using a Unix-like operating system you can start your REPL using
rlwrap
. This would give you Ctrl-R for accessing commands from history in an easy way, as well as storing the history itself.You'd just have to install
rlwrap
and prepend it to the line where you start REPL, e.g.rlwrap lein repl
几个提示:
Couple of tips:
这实际上是一个比看起来更难的问题,因为这样的转储必须考虑符号和变量依赖性,并以正确的符号顺序输出到文件。也就是说,由于代码就是数据,因此我们应该能够编写一个函数来执行此操作。
This is actually a harder problem than it seems because a dump like this must take into account symbol and vars dependencies and output to file in the correct order of symbols. That said since code is data one should be able to write a function that does that.