如何编写Clojure REPL应用程序?

如何编写Clojure REPL应用程序?,clojure,Clojure,我想以Clojure REPL的形式提供一份申请。也就是说,用户从终端运行的东西,有一个完整的Clojure REPL,其中包含一系列额外的功能作为Clojure函数 我希望整个过程都生活在一个独立的JAR中,而不是依赖于已经安装了Clojure的用户,或者知道如何安装Clojure或导入额外的库。当你跑的时候,所有的东西都应该在那里 有没有一种简单的方法可以做到这一点?即,重用现有的Clojure REPL代码?您所要做的就是在自己的main中运行 这些文件解释了您拥有的入口点: 这里要做的常

我想以Clojure REPL的形式提供一份申请。也就是说,用户从终端运行的东西,有一个完整的Clojure REPL,其中包含一系列额外的功能作为Clojure函数

我希望整个过程都生活在一个独立的JAR中,而不是依赖于已经安装了Clojure的用户,或者知道如何安装Clojure或导入额外的库。当你跑的时候,所有的东西都应该在那里


有没有一种简单的方法可以做到这一点?即,重用现有的Clojure REPL代码?

您所要做的就是在自己的main中运行

这些文件解释了您拥有的入口点:

这里要做的常见事情:

  • :init
    :添加您自己的设置以供REPL使用。例如,
    使用一些库
  • :提示
    :显示与ns不同的“状态”
  • :打印
    :使用某种漂亮的打印机
值得一提的是,您构建的每个包含
clojure.main
(例如
clojure-$VERSION.jar
)的程序(例如uberjar)都可以从该uberjar运行REPL,因此您可以从那里运行不同的
main
:s

自我宣传:如果你需要进一步的灵感,这些是我过去做过的“修改”回复:

  • :添加用于使用JSON/XMLAPI的有状态URL导航和工具
  • :使用integrant为REPL生成基于模块的合成
"Generic, reusable, read-eval-print loop. By default, reads from *in*,
writes to *out*, and prints exception summaries to *err*. If you use the
default :read hook, *in* must either be an instance of
LineNumberingPushbackReader or duplicate its behavior of both supporting
.unread and collapsing CR, LF, and CRLF into a single \\newline. Options
are sequential keyword-value pairs. Available options and their defaults:
   - :init, function of no arguments, initialization hook called with
     bindings for set!-able vars in place.
     default: #()
   - :need-prompt, function of no arguments, called before each
     read-eval-print except the first, the user will be prompted if it
     returns true.
     default: (if (instance? LineNumberingPushbackReader *in*)
                #(.atLineStart *in*)
                #(identity true))
   - :prompt, function of no arguments, prompts for more input.
     default: repl-prompt
   - :flush, function of no arguments, flushes output
     default: flush
   - :read, function of two arguments, reads from *in*:
       - returns its first argument to request a fresh prompt
         - depending on need-prompt, this may cause the repl to prompt
           before reading again
       - returns its second argument to request an exit from the repl
       - else returns the next object read from the input stream
     default: repl-read
   - :eval, function of one argument, returns the evaluation of its
     argument
     default: eval
   - :print, function of one argument, prints its argument to the output
     default: prn
   - :caught, function of one argument, a throwable, called when
     read, eval, or print throws an exception or error
     default: repl-caught"