[英]Cannot “use” in clojurescript repl
我在Clojurescript命名空間鍵入以下內容。
cljs.user> (use '[clojure.zip :only [insert-child]])
WARNING: Use of undeclared Var cljs.user/use at line 1
"Error evaluating:" (use (quote [clojure.zip :only [insert-child]])) :as "cljs.user.use.call(null,cljs.core.vec([\"\\uFDD1'clojure.zip\",\"\\uFDD0'only\",cljs.core.vec([\"\\uFDD1'insert-child\"])]));\n"
#<TypeError: Cannot call method 'call' of undefined>
TypeError: Cannot call method 'call' of undefined
at eval (eval at <anonymous> (http://localhost:3000/main.js:32728:147), <anonymous>:1:85)
at eval (eval at <anonymous> (http://localhost:3000/main.js:32728:147), <anonymous>:6:3)
at http://localhost:3000/main.js:32728:142
at evaluate_javascript (http://localhost:3000/main.js:32741:4)
at Object.callback (http://localhost:3000/main.js:32806:138)
at goog.messaging.AbstractChannel.deliver (http://localhost:3000/main.js:31059:13)
at goog.net.xpc.CrossPageChannel.deliver_ (http://localhost:3000/main.js:32164:14)
at Function.goog.net.xpc.NativeMessagingTransport.messageReceived_ (http://localhost:3000/main.js:31732:13)
at goog.events.Listener.handleEvent (http://localhost:3000/main.js:22590:26)
at Object.goog.events.fireListener (http://localhost:3000/main.js:22924:21)
nil
似乎在說明cljs.user命名空間中不存在'use'方法。 這種方式對我來說很有意義,因為Clojurescript本身無法評估Clojure表達式。 但是,我知道Clojurescript有一個clojure.zip命名空間,我在命名空間聲明中(:use [clojure.zip :only [insert-child]])
。
如何在Clojurescript repl中使用clojure.zip的Clojurescript版本?
由於ClojureScript命名空間的實現方式與Clojure完全不同,因此ClojureScript不支持直接use
或require
表單。
相反,您必須使用ns
宏。 要在cljs.user
命名空間中使用clojure.zip
,請執行以下操作:
(ns cljs.user (:use [clojure.zip :only [insert-child]]))
請注意, ns
的ClojureScript版本支持的表單是Clojure支持的表單的子集; 具體來說, :use
子句必須指定:only
form,而:require
子句必須指定:as
form。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.