简体   繁体   中英

Clojure core.async and clojure.core namespace elements appear to collide

I'm attempting to tinker with Cursive , a plugin for Intellij for the Clojure language. I've imported a very standard new application via Lein , and now attempting to much around with a few core.async constructs.

Here's the project definition:

(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"]])

And the source:

(ns app.core)

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

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

Basic Clojure constructs work without any issue. But after adding the core.async dependency in Lein, each time I attempt to run a piece of code these warnings crop up:

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

It appears to be a namespace collision of sorts.

Is there a simple means to resolve this?

The reason namespaces exist is to give context to names so that they can be reused. This is just an example of that. By using :refer :all you are attempting to pull in many functions that conflict with clojure.core functions. I usually bring only a subset of the more syntactic elements of core.async into my ns and create an alias for the rest:

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

Most of the overlapping names are actually now deprecated and will be removed in the future as they are no longer needed with transducers. For example, instead of using clojure.core.async.take, you will create a chan with a clojure.core.take transducer with Clojure 1.7.

Turns out there's a means to exclude elements. Its a bit cludgy as I'd imagine core.async is popular enough there'd be a default means to avoid basic name collisions. But alas, here's the modified ns/require statement which got me up and running:

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

Discovered here on Github

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM