Ced*_*tin 3 browser emacs read-eval-print-loop clojurescript
我正在尝试在浏览器中启动ClojureScript REPL.理想情况下我还不想使用Austin:我首先想要让最简单的REPL工作.
我尝试了各种教程,到目前为止我没有设法让它工作.基本上我不明白人们说:"启动ClojureScript浏览器REPL"时的含义.
到目前为止我做了:
lein new mies hellow
Run Code Online (Sandbox Code Playgroud)
和:
lein cljsbuild auto hellow
Run Code Online (Sandbox Code Playgroud)
这是我的core.js文件:
(ns hellow.core
(:require [clojure.browser.repl :as repl]))
(enable-console-print!)
(println "Hello world!")
(. js/console (log "Hello again"))
(repl/connect "http://localhost:9000/repl")
(. js/console (log "Ah, this prints too"))
Run Code Online (Sandbox Code Playgroud)
当我打开index.html(调用core.js)时,我可以在Chrome的开发人员工具的JavaScript控制台中看到所有内容都已正确记录.
但(repl/connect ...)
显然失败了.这是Chrome的开发者工具所展示的内容;
Failed to load resource http://localhost:9000/repl?xpc=%7B%22cn%22%...
Run Code Online (Sandbox Code Playgroud)
在几乎所有关于ClojureScript的论坛帖子/博客文章/教程中我都读过这个主题,我偶然发现了一句话:"启动浏览器REPL"或类似内容.
如何启动浏览器REPL?这是在从浏览器加载index.html 之前必须完成的事情吗?
我可以从Emacs启动这个浏览器REPL吗?
如何在不加载index.html/core.js的情况下测试浏览器REPL是否正常工作?
我怎样才能然后确认,之后的index.html/core.js被加载到浏览器中,该(REPL /连接...)内core.js所做的工作,实际上是连接到REPL?
启动repl服务器(您已经包含客户端代码)的最简单和最基本的方法就是这样做
$ lein trampoline cljsbuild repl-listen
Running ClojureScript REPL, listening on port 9000.
To quit, type: :cljs/quit
ClojureScript:cljs.user>
Run Code Online (Sandbox Code Playgroud)
此时,如果您尝试eval任何表达式(+ 1 2)
,例如,您将看到repl挂起,因为它没有eval的环境.
那是你去index.html的时候(记得从web服务器上提供服务,或者连接失败,不要使用file:///
网址)并在浏览器上打开它.
连接http://localhost:9000/repl?xpc=...
应该工作正常,并且repl应该解锁并打印3
.从那时起,任何命令都将在浏览器环境中执行.
我想尝试(js/alert "hi")
查看repl是否已连接,如果它正常工作,它将alert
在浏览器窗口中输入.
请记住,浏览器窗口是您的执行环境,因此如果您刷新它,您将丢失运行时值,如果您不再次定义它们,则无法从repl访问它们.
使用cljsbuild还有:( lein cljsbuild help
)
repl-listen
Run a REPL that will listen for incoming connections. (the one I used above)
repl-launch
Run a REPL and launch a custom command to connect to it.
repl-rhino
Run a Rhino-based REPL (JVM based JS execution environment, no browser needed).
Run Code Online (Sandbox Code Playgroud)
此外,对于准系统repl,将它与rlwrap一起使用以获取readline快捷方式(Ctrl + a等)和repl历史记录以及其他内容非常有用:
$ rlwrap lein trampoline cljsbuild repl-listen
Run Code Online (Sandbox Code Playgroud)
我希望这一切都有所帮助.
归档时间: |
|
查看次数: |
1461 次 |
最近记录: |