Clojure warning: “resultset-seq already exists in clojure.core”

两盒软妹~` 提交于 2021-01-27 08:10:24

问题


I'm new to Clojure and building a web app using the Noir framework (very similar to Compojure, in fact I think it's Compojure with a different request handler layer). I'm getting a warning when I import the JDBC library:

WARNING: resultset-seq already refers to: #'clojure.core/resultset-seq in namespace: webapp.models.database, being replaced by: #'clojure.java.jdbc/resultset-seq

Do I have to live with this warning or is there a way around it? I'm importing the JDBC library using:

(use 'clojure.java.jdbc)

回答1:


You can avoid the problem by specifying the exact bindings to be imported:

(use '[clojure.java.jdbc :only [insert-values transaction]])
(transaction
  (insert-values ...))

Another option is to :exclude the offending binding:

(use '[clojure.java.jdbc :exclude [resultset-seq]])
(transaction
  (insert-values ...))

You can also just use require instead:

(require '[clojure.java.jdbc :as db])
(db/transaction
  (db/insert-values ...))

With regard to forward compatibility, require is arguably safest. Using :only is just slightly less clean but still a pretty good approach (and easy to fix when it breaks). Excluding the currently offending bindings is probably the least future-proof way of fixing the problem since other conflicting bindings can appear at any time and tracking down what is imported from where can be tricky.




回答2:


There are lots of options. What this warning means is, that you are replacing an already defined symbol with a definition from different package. In this case, it looks like this is a variable that you've defined, right? If so the easiest solution might be to just rename it in your code.

Or if you don't need the resultset-seq from clojure.java.jdbc package you can exclude it:

(use '[clojure.java.jdbc :exclude (resultset-seq)])

or better yet,

(use '[clojure.java.jdbc :only (f1 f2 f3)])

where f1, f2, f3 are the things you're actually need.

(use '[clojure.java.jdbc :as jdbc])

and then use jdbc/resultset-seq

Or you can just:

(require 'clojure.java.jdbc)

and then use clojure.java.jdbc/reusltset-seq




回答3:


In addition to the other excellent answers, if you want the jdbc resultset-seq instead of the core one, you can exclude the latter from being brought into the current ns:

(ns foo
  (:refer-clojure :exclude [resultset-seq])
  (:use clojure.java.jdbc))


来源:https://stackoverflow.com/questions/8233434/clojure-warning-resultset-seq-already-exists-in-clojure-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!