[英]Why map in clojure is returning an async chan rather than a sequence of strings?
I am new to clojure and currently stuck with the map function.I tried the following code: 我是clojure的新手,目前仍然坚持使用map函数。我尝试了以下代码:
(map #(str "Hello " % "!" ) ["Ford" "Arthur" "Tricia"])
it's returning: 它正在回归:
#object[clojure.core.async.impl.channels.ManyToManyChannel 0x2eaf8b7c "clojure.core.async.impl.channels.ManyToManyChannel@2eaf8b7c"]
though i wanted: 虽然我想:
("Hello Ford!" "Hello Arthur!" "Hello Tricia!"])
I was following the clojure.core/map
documentation example but it isn't working as expected.. 我正在关注
clojure.core/map
文档示例,但它没有按预期工作..
It looks like you have probably replaced clojure.core/map
with clojure.core.async/map
. 看起来你可能用
clojure.core/map
替换了clojure.core.async/map
。 The most common way this would happen is by doing something at your repl like this (note the many warnings that tell you about this when you do so): 这种情况最常见的方式是在你的repl上做这样的事情(注意当你这样做的时候会有很多警告告诉你):
user=> (use 'clojure.core.async)
WARNING: reduce already refers to: #'clojure.core/reduce in namespace: user, being replaced by: #'clojure.core.async/reduce
WARNING: take already refers to: #'clojure.core/take in namespace: user, being replaced by: #'clojure.core.async/take
WARNING: map already refers to: #'clojure.core/map in namespace: user, being replaced by: #'clojure.core.async/map
WARNING: transduce already refers to: #'clojure.core/transduce in namespace: user, being replaced by: #'clojure.core.async/transduce
WARNING: into already refers to: #'clojure.core/into in namespace: user, being replaced by: #'clojure.core.async/into
WARNING: partition already refers to: #'clojure.core/partition in namespace: user, being replaced by: #'clojure.core.async/partition
WARNING: merge already refers to: #'clojure.core/merge in namespace: user, being replaced by: #'clojure.core.async/merge
WARNING: partition-by already refers to: #'clojure.core/partition-by in namespace: user, being replaced by: #'clojure.core.async/partition-by
You can always refer unambiguously to a function with it's qualified name: 您始终可以使用其限定名称明确地引用函数:
(clojure.core/map #(str "Hello " % "!" ) ["Ford" "Arthur" "Tricia"])
Generally, though it's best to avoid using use
and instead require
the other namespace and give it an alias instead: 通常,尽管最好避免使用
use
,而是require
另一个名称空间并为其指定别名:
(require '[clojure.core.async :as async])
That way, your clojure.core/map
can still be used as map
(as all clojure.core functions are auto-referred) and the async version can be referred to as async/map
. 这样,你的
clojure.core/map
仍然可以用作map
(因为所有的clojure.core函数都是自动引用的),async版本可以称为async/map
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.