简体   繁体   中英

Why am I having to add a dependency to org.clojure/clojure-contrib to use dissoc-in?

After creating a project with $ lein new app my-proj , I cannot import clojure.contrib.core in order to use dissoc-in.

$ lein repl
REPL-y 0.3.0
Clojure 1.5.1
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

my-proj.core=> (require '[clojure.contrib.core :as cc])

FileNotFoundException Could not locate clojure/contrib/core__init.class or clojure/contrib/core.clj on classpath:   clojure.lang.RT.load (RT.java:443)

loaded-libs shows that the clojure.contrib.core lib is not loaded:

my-proj.core=> (loaded-libs)
#{clojure.core.protocols clojure.instant clojure.java.browse clojure.java.io clojure.java.javadoc clojure.java.shell clojure.main clojure.pprint clojure.repl clojure.set clojure.stacktrace clojure.string clojure.template clojure.test clojure.tools.nrepl clojure.tools.nrepl.ack clojure.tools.nrepl.bencode clojure.tools.nrepl.middleware clojure.tools.nrepl.middleware.interruptible-eval clojure.tools.nrepl.middleware.load-file clojure.tools.nrepl.middleware.pr-values clojure.tools.nrepl.middleware.session clojure.tools.nrepl.misc clojure.tools.nrepl.server clojure.tools.nrepl.transport clojure.uuid clojure.walk complete.core my-proj.core}

However, If I add a dependency to [org.clojure/clojure-contrib "1.2.0"] in my project.clj, I can require clojure.contrib.core and use dissoc-in as advertised. From what I've read from this answer , this should not be necessary. What am I doing wrong?

There is no dissoc-in function in the core language, though it is available in the incubator project . Using the 1.2 clojure.contrib in modern Clojure is entirely unsupported and if it works, thats just a fluke. It may be best to not include it. Either use the one from the incubator or use update-in

these days people tend to use

(update-in my-map [:key1 :key2] dissoc :key-to-remove) 

for example:

user> (update-in {:a {:b {:c 1 :d 2}}} [:a :b] dissoc :c) 
{:a {:b {:d 2}}}

If you would like to see this feature added, vote for this Jira issue

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