Clojure core.async和clojure.core名称空间元素似乎发生冲突

时间:2014-10-03 05:12:23

标签: asynchronous intellij-idea clojure

我试图修改Cursive,这是一个针对Clojure语言的Intellij插件。我已经通过Lein导入了一个非常标准的新应用程序,现在尝试使用一些core.async构造。

这是项目定义:

(defproject app "0.1.0-SNAPSHOT"
  :description "Clojure project illustrating basic core.async constructs"
  :dependencies [[org.clojure/clojure "1.5.1"]
             [org.clojure/core.async "0.1.346.0-17112a-alpha"]])

来源:

(ns app.core)

(require '[clojure.core.async :as async :refer :all])

(let [c (chan 10)]
  (>!! c "hello")
  (println (<!! c))
  (close! c))

基本的Clojure构造工作没有任何问题。但是在Lein中添加core.async依赖项之后,每次我尝试运行一段代码时都会出现这些警告:

WARNING: partition-by already refers to: #'clojure.core/partition-by in namespace: app.core, being replaced by: #'clojure.core.async/partition-by
WARNING: map already refers to: #'clojure.core/map in namespace: app.core, being replaced by: #'clojure.core.async/map
WARNING: into already refers to: #'clojure.core/into in namespace: app.core, being replaced by: #'clojure.core.async/into
WARNING: reduce already refers to: #'clojure.core/reduce in namespace: app.core, being replaced by: #'clojure.core.async/reduce
WARNING: partition already refers to: #'clojure.core/partition in namespace: app.core, being replaced by: #'clojure.core.async/partition
WARNING: take already refers to: #'clojure.core/take in namespace: app.core, being replaced by: #'clojure.core.async/take
WARNING: merge already refers to: #'clojure.core/merge in namespace: app.core, being replaced by: #'clojure.core.async/merge

它似乎是各种命名空间的冲突。

有没有简单的方法来解决这个问题?

2 个答案:

答案 0 :(得分:5)

存在命名空间的原因是为名称提供上下文,以便可以重用它们。这只是一个例子。通过使用:参考:你试图引入许多与clojure.core函数冲突的函数。我通常只将core.async的更多语法元素的一部分带入我的ns并为其余部分创建一个别名:

(require '[clojure.core.async :as async :refer [>! <! >!! <!! go]])

大多数重叠名称实际上已被弃用,将来将被删除,因为换能器不再需要它们。例如,不是使用clojure.core.async.take,而是使用Clojure 1.7创建一个带有clojure.core.take传感器的chan。

答案 1 :(得分:1)

原来有一种排除元素的方法。它有点笨拙,因为我认为core.async很受欢迎,有一种默认方法可以避免基本名称冲突。但是,唉,这是修改后的ns / require语句让我开始运行:

(ns app.core
  (:refer-clojure :exclude [map reduce into partition partition-by take merge])
  (:require [clojure.core.async :refer :all :as async]))

发现了here on Github