Clojurescript clojure.set 不工作
Clojurescript clojure.set not working
我已经引用了 ClojureScript clojure.set? 并且只能得到文档字符串,但实际上 运行 任何 clojure.set
函数都不起作用。在 Opera 28.0 and/or Chrome 上使用 ClojureScript 0.0-3126 Windows 7 x64.
41.0.2272.101 m
关于如何更正此问题的任何想法?
谢谢
ClojureScript:cljs.user> (require '[clojure.set])
nil
ClojureScript:cljs.user> (doc clojure.set/union)
-------------------------
clojure.set/union
([] [s1] [s1 s2] [s1 s2 & sets])
Return a set that is the union of the input sets
nil
ClojureScript:cljs.user> (clojure.set/union #{:a} #{:b})
TypeError: Cannot read property 'union' of undefined
TypeError: Cannot read property 'union' of undefined
at eval (eval at <anonymous> (http://localhost:8888/js/coreweb.js:45250:260), <anonymous>:1:100)
at eval (eval at <anonymous> (http://localhost:8888/js/coreweb.js:45250:260), <anonymous>:9:3)
at eval (ev al at <anonymous> (http://localhost:8888/js/coreweb.js:45250:260), <anonymous>:14:4)
at http://localhost:8888/js/coreweb.js:45250:255
at clojure$browser$repl$evaluate_javascript (http://localhost:8888/js/coreweb.js:45256:4)
at Object.callback (http://localhost:8888/js/coreweb.js:45421:181)
at goog.messaging.AbstractChannel.deliver (http://localhost:8888/js/coreweb.js:42499:13)
at goog.net.xpc.CrossPageChannel.xpcDeliver (http://localhost:8888/js/coreweb.js:43463:14)
at Function.goog.net.xpc.NativeMessagingTransport.messageReceived_ (http://localhost:8888/js/coreweb.js:42859:13)
at Object.goog.events.fireListener (http://localhost:8888/js/coreweb.js:39835:21)
与其说是答案,不如说是个人研究。不过,我确实在 Chrome(在 MAC 上)使用 ClojureScript Quick Start.
重现了您的问题
如果 cljs 服务器 repl 文件如下(即 clojure.set
上没有 require
):
(ns hello-world.core
(:require [clojure.browser.repl :as repl]))
(defonce conn
(repl/connect "http://localhost:9000/repl"))
(enable-console-print!)
(println "Hello world!")
而 repl.clj
是:
(require 'cljs.repl)
(require 'cljs.closure)
(require 'cljs.repl.browser)
(cljs.closure/build "src"
{:main 'hello-world.core
:output-to "out/main.js"
:verbose true})
(cljs.repl/repl (cljs.repl.browser/repl-env)
:watch "src"
:output-dir "out")
然后在终端中启动 repl:
rlwrap java -cp cljs.jar:src clojure.main repl.clj
并在 http://localhost:9000
上连接浏览器,然后就可以了:
ClojureScript:cljs.user> (require '[clojure.set])
nil
ClojureScript:cljs.user> (clojure.set/union #{6} #{9} #{7})
#{7 6 9}
现在,如果您 重新加载 服务器页面 http://localhost:9000
,然后重试,我遇到了问题(文档可在 symbol,但是 var 已经不存在了):
ClojureScript:cljs.user> (doc clojure.set/union)
-------------------------
clojure.set/union
([] [s1] [s1 s2] [s1 s2 & sets])
Return a set that is the union of the input sets
nil
ClojureScript:cljs.user> (clojure.set/union #{6} #{9} #{7})
TypeError: Cannot read property 'union' of undefined
TypeError: Cannot read property 'union' of undefined
at eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:42:272), <anonymous>:1:100)
如果修改cljs服务器文件为require
clojure.set
,即
(ns hello-world.core
(:require [clojure.browser.repl :as repl]
[clojure.set]))
然后,看起来你仍然需要从 repl 中请求 clojure.set 才能使用它的功能,但是,你可以重新加载服务器页面,它仍然可以在 repl 中工作。
我已经引用了 ClojureScript clojure.set? 并且只能得到文档字符串,但实际上 运行 任何 clojure.set
函数都不起作用。在 Opera 28.0 and/or Chrome 上使用 ClojureScript 0.0-3126 Windows 7 x64.
关于如何更正此问题的任何想法? 谢谢
ClojureScript:cljs.user> (require '[clojure.set])
nil
ClojureScript:cljs.user> (doc clojure.set/union)
-------------------------
clojure.set/union
([] [s1] [s1 s2] [s1 s2 & sets])
Return a set that is the union of the input sets
nil
ClojureScript:cljs.user> (clojure.set/union #{:a} #{:b})
TypeError: Cannot read property 'union' of undefined
TypeError: Cannot read property 'union' of undefined
at eval (eval at <anonymous> (http://localhost:8888/js/coreweb.js:45250:260), <anonymous>:1:100)
at eval (eval at <anonymous> (http://localhost:8888/js/coreweb.js:45250:260), <anonymous>:9:3)
at eval (ev al at <anonymous> (http://localhost:8888/js/coreweb.js:45250:260), <anonymous>:14:4)
at http://localhost:8888/js/coreweb.js:45250:255
at clojure$browser$repl$evaluate_javascript (http://localhost:8888/js/coreweb.js:45256:4)
at Object.callback (http://localhost:8888/js/coreweb.js:45421:181)
at goog.messaging.AbstractChannel.deliver (http://localhost:8888/js/coreweb.js:42499:13)
at goog.net.xpc.CrossPageChannel.xpcDeliver (http://localhost:8888/js/coreweb.js:43463:14)
at Function.goog.net.xpc.NativeMessagingTransport.messageReceived_ (http://localhost:8888/js/coreweb.js:42859:13)
at Object.goog.events.fireListener (http://localhost:8888/js/coreweb.js:39835:21)
与其说是答案,不如说是个人研究。不过,我确实在 Chrome(在 MAC 上)使用 ClojureScript Quick Start.
重现了您的问题如果 cljs 服务器 repl 文件如下(即 clojure.set
上没有 require
):
(ns hello-world.core
(:require [clojure.browser.repl :as repl]))
(defonce conn
(repl/connect "http://localhost:9000/repl"))
(enable-console-print!)
(println "Hello world!")
而 repl.clj
是:
(require 'cljs.repl)
(require 'cljs.closure)
(require 'cljs.repl.browser)
(cljs.closure/build "src"
{:main 'hello-world.core
:output-to "out/main.js"
:verbose true})
(cljs.repl/repl (cljs.repl.browser/repl-env)
:watch "src"
:output-dir "out")
然后在终端中启动 repl:
rlwrap java -cp cljs.jar:src clojure.main repl.clj
并在 http://localhost:9000
上连接浏览器,然后就可以了:
ClojureScript:cljs.user> (require '[clojure.set])
nil
ClojureScript:cljs.user> (clojure.set/union #{6} #{9} #{7})
#{7 6 9}
现在,如果您 重新加载 服务器页面 http://localhost:9000
,然后重试,我遇到了问题(文档可在 symbol,但是 var 已经不存在了):
ClojureScript:cljs.user> (doc clojure.set/union)
-------------------------
clojure.set/union
([] [s1] [s1 s2] [s1 s2 & sets])
Return a set that is the union of the input sets
nil
ClojureScript:cljs.user> (clojure.set/union #{6} #{9} #{7})
TypeError: Cannot read property 'union' of undefined
TypeError: Cannot read property 'union' of undefined
at eval (eval at <anonymous> (http://localhost:9000/out/clojure/browser/repl.js:42:272), <anonymous>:1:100)
如果修改cljs服务器文件为require
clojure.set
,即
(ns hello-world.core
(:require [clojure.browser.repl :as repl]
[clojure.set]))
然后,看起来你仍然需要从 repl 中请求 clojure.set 才能使用它的功能,但是,你可以重新加载服务器页面,它仍然可以在 repl 中工作。