首页 文章

Clojure控制台在简单的HelloWorld上发出'unsigned-bit-shift-right'警告

提问于
浏览
2

我今天正在与Clojure迈出第一步,我遇到了第一个令人困惑的障碍!

我已经构建了一个新的Leiningen(2.5.1)项目,只想运行默认代码,即:

(ns wavescript.core
  (:gen-class))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!"))

问题是Lighttable(0.7.2)控制台告诉:

警告:unsigned-bit-shift-right已经引用:命名空间中的''clojure.core / unsigned-bit-shift-right:cljs.core,被替换为:#'cljs.core / unsigned-bit-shift-对

我找到了一些谷歌条目,但没有一个带我进一步 . 这是关于什么的?

1 回答

  • 5

    这是由clojure.core命名空间中的符号unsigned-bit-shift-right以及cljs.core引起的 . clojure.core命名空间在cljs.core之前被编译/加载,并且新符号的引入正在抛出警告 . 从命名空间看,您正在编写clojurescript . 如果您在2147行查看此文件cljs.core,您将看到以下表单:

    (defn unsigned-bit-shift-right
      "Bitwise shift right with zero fill"
      [x n] (cljs.core/unsigned-bit-shift-right x n))
    

    在cljs.core命名空间中 . 所以,显然,lighttable正在导入clojure.core和clj.core .

    老实说,我甚至不确定cljs的实现是如何工作的,因为它完全是自我指涉的 . 另外,从第451行开始使用无符号位移右边没有前缀,因此它们必须使用clojure.core实现 . 离奇 . 上述表格在所有之前的用途之后出现 . 可以安全地说,可以安全地排除符号 . 事实上,这可能值得一个补丁......

    要解决此问题,您可能希望尝试显式声明命名空间导入并排除该导入 . refer函数提供了这个功能 .

    所以,你会有一个看起来像这样的命名空间

    (ns my.namespace.hello-world
      [:require 
        [cljs.core :exclude [unsigned-bit-shift-right]]])
    

    clojure.core实现如下所示:

    (defn unsigned-bit-shift-right
      "Bitwise shift right, without sign-extension."
      {:inline (fn [x n] `(. clojure.lang.Numbers (unsignedShiftRight ~x ~n)))
       :added "1.6"}
      [x n] (. clojure.lang.Numbers unsignedShiftRight x n))
    

    或者,由于它们正在包装功能,因此cljs.core可能不需要公开clojure.core . 如果是这种情况,那么排除clojure.core,看看你的代码是否能正常运行 .

    实际上,从查看cljs.core命名空间:

    (ns cljs.core
      (:refer-clojure :exclude [-> ->> .. amap and areduce alength aclone assert binding bound-fn case comment cond condp
                                declare definline definterface defmethod defmulti defn defn- defonce
                                defprotocol defrecord defstruct deftype delay destructure doseq dosync dotimes doto
                                extend-protocol extend-type fn for future gen-class gen-interface
                                if-let if-not import io! lazy-cat lazy-seq let letfn locking loop
                                memfn ns or proxy proxy-super pvalues refer-clojure reify sync time
                                when when-first when-let when-not while with-bindings with-in-str
                                with-loading-context with-local-vars with-open with-out-str with-precision with-redefs
                                satisfies? identical? true? false? number? nil? instance? symbol? keyword? string? str get
                                make-array vector list hash-map array-map hash-set
    
                                aget aset
                                + - * / < <= > >= == zero? pos? neg? inc dec max min mod
                                byte char short int long float double
                                unchecked-byte unchecked-char unchecked-short unchecked-int
                                unchecked-long unchecked-float unchecked-double
                                unchecked-add unchecked-add-int unchecked-dec unchecked-dec-int
                                unchecked-divide unchecked-divide-int unchecked-inc unchecked-inc-int
                                unchecked-multiply unchecked-multiply-int unchecked-negate unchecked-negate-int
                                unchecked-subtract unchecked-subtract-int unchecked-remainder-int
                                unsigned-bit-shift-right
    
                                bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set
                                bit-test bit-shift-left bit-shift-right bit-xor
    
                                cond-> cond->> as-> some-> some->>
    
                                if-some when-some test ns-interns var vswap!])
    

    您可以看到unsigned-bit-shift-right应该从命名空间中排除 . 因此,您需要排除clojure.core以解决问题 .

相关问题