最简单的获取ClojureScript REPL的方法

3

如何在终端中快速启动ClojureScript REPL?我不需要连接浏览器,只需要REPL来评估表达式。

文档似乎假定您要进行浏览器同步,或者提供复杂的技巧来获得简单的REPL。

1个回答

5
请看最近发布的 ClojureScript / wiki / Quick-Start指南。它实际上是迄今为止最简单和最基本的。
基本上(假设您已经安装了Java 8和node.js):
  1. Download the latest jar from here https://github.com/clojure/clojurescript/releases/ and put it in a folder
  2. Using instructions from here https://github.com/clojure/clojurescript/wiki/Quick-Start#nodejs-repl as inspiration:

  3. Create node_repl.clj where you have the jar file with this contents:

    (require 'cljs.repl)
    (require 'cljs.repl.node)
    
    (cljs.repl/repl (cljs.repl.node/repl-env))
    
  4. Execute with java -cp cljs.jar clojure.main node_repl.clj. This should open the repl, like this:

    $ java -cp cljs.jar clojure.main node_repl.clj
    ClojureScript Node.js REPL server listening on 50658
    To quit, type: :cljs/quit
    ClojureScript:cljs.user> (+ 1 2)
    3
    
如果你想要一个更高级的repl,请按照指南上所述使用rlwraprlwrap java -cp cljs.jar clojure.main node_repl.clj)。
再次提醒,请查看那份快速入门指南,它真的很棒(感谢Swannodette)。

编辑

如果您希望不使用node.js获取可工作的repl,可以使用nashorn(java 8 js虚拟机)或rhino(旧版基于java的js虚拟机),将步骤3和4替换为以下步骤:

对于Nashorn

  1. Create nashorn_repl.clj where you have the jar file with this contents:

    (require 'cljs.repl)
    (require 'cljs.repl.nashorn)
    
    (cljs.repl/repl (cljs.repl.nashorn/repl-env))
    
  2. Execute with java -cp cljs.jar clojure.main nashorn_repl.clj. This should open the repl, like this:

    $ java -cp cljs.jar clojure.main nashorn_repl.clj
    To quit, type: :cljs/quit
    ClojureScript:cljs.user> (+ 1 2)
    3
    

对于Rhino

  1. Create rhino_repl.clj where you have the jar file with this contents:

    (require 'cljs.repl)
    (require 'cljs.repl.rhino)
    
    (cljs.repl/repl (cljs.repl.rhino/repl-env))
    
  2. Execute with java -cp cljs.jar clojure.main rhino_repl.clj. This should open the repl, like this:

    $ java -cp cljs.jar clojure.main rhino_repl.clj
    To quit, type: :cljs/quit
    ClojureScript:cljs.user> (+ 1 2)
    3
    

感谢您花费时间进行解释,非常清晰易懂。不幸的是,仅凭这些步骤似乎还不够:我遇到了一个“Exception in thread "main" java.io.FileNotFoundException: Could not locate cljs/repl'__init.class or cljs/repl'.clj on classpath: , compiling:(/Users/sergi/lib/node_repl.clj:1:1)”错误。 - Sergi Mansilla
现在已经解决了。快速入门教程中的代码有一个错别字:https://groups.google.com/forum/#!topic/clojurescript/tV26-cGIXrA - Sergi Mansilla
太棒了 :) 在开始的时候引用是令人困惑的! - Joaquin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接