使用 clojure.string 会导致警告
使用 clojure.string 时,我的 clojure 脚本收到以下警告
WARNING: replace already refers to: #'clojure.core/replace in namespace: tutorial.regexp, being replaced by: #'clojure.string/replace
WARNING: reverse already refers to: #'clojure.core/reverse in namespace: tutorial.regexp, being replaced by: #'clojure.string/reverse
:
(ns play-with-it
(:use [clojure.string]))
有没有办法修复这些警告?
When using clojure.string, I receive the following warnings
WARNING: replace already refers to: #'clojure.core/replace in namespace: tutorial.regexp, being replaced by: #'clojure.string/replace
WARNING: reverse already refers to: #'clojure.core/reverse in namespace: tutorial.regexp, being replaced by: #'clojure.string/reverse
my clojure script is:
(ns play-with-it
(:use [clojure.string]))
Is there any way to fix those warnings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,切换到
,然后说例如
调用
clojure.string
的replace
函数。使用
:use
,您可以将clojure.string
中的所有变量直接引入到您的命名空间中,因为其中一些变量的名称与clojure.core< 中的变量发生冲突。 /code>,您会收到警告。然后,您必须说
clojure.core/replace
才能获得通常简称为replace
的内容。名字的冲突是有意而为之的。
clojure.string
意味着需要使用这样的别名。str
和string
是最常选择的别名。Yes, switch to
and then say e.g.
to call
clojure.string
'sreplace
function.With
:use
, you bring in all Vars fromclojure.string
directly into your namespace, and since some of those have names clashing with Vars inclojure.core
, you get the warning. Then you'd have to sayclojure.core/replace
to get at what's usually simply calledreplace
.The clash of names is by design;
clojure.string
is meant to berequire
d with an alias like this.str
andstring
are the most frequently chosen aliases.除了 Michał 的回答之外,您还可以从 clojure.core 中排除变量:
In addition to Michał's answer, you can exclude vars from
clojure.core
:除了亚历克斯的答案之外,您还可以仅从给定的命名空间引用您想要的变量。
这不会引发警告,因为
replace-first
不在clojure.core
中。但是,如果执行以下操作,您仍然会收到警告:一般来说,人们似乎倾向于
(ns foo.bar (:require [foo.bar :as baz]))
。In addition to Alex's answer you can also refer only the vars you want from a given namespace.
This would not throw a warning since
replace-first
is not inclojure.core
. However, you would still receive a warning if you did the following:In general it seems people are tending toward
(ns foo.bar (:require [foo.bar :as baz]))
.从 Clojure 1.4 开始,您可以使用
:require
和:refer
从命名空间引用您需要的各个函数:现在推荐使用
:use
。假设您不需要 clojure.string/replace 或 clojure.string/reverse ,这也会删除警告。
请参阅这个问题和此 JIRA 问题了解更多详细信息。
Since Clojure 1.4 you can refer the individual functions you need from a namespace using
:require
with a:refer
:This is now recommended over
:use
.Assuming you don't need the
clojure.string/replace
orclojure.string/reverse
, that would also remove the warnings.See this SO question and this JIRA issue for more details.