This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-15
Channels
- # aleph (5)
- # bangalore-clj (1)
- # beginners (53)
- # boot (1)
- # cljs-dev (327)
- # cljsrn (3)
- # clojure (16)
- # clojure-filipino (47)
- # clojure-nlp (4)
- # clojure-russia (1)
- # clojure-spec (3)
- # clojurescript (64)
- # core-async (6)
- # datomic (25)
- # hoplon (5)
- # jobs (5)
- # klipse (2)
- # lein-figwheel (2)
- # lumo (27)
- # om (2)
- # onyx (6)
- # parinfer (4)
- # pedestal (1)
- # protorepl (1)
- # re-frame (31)
- # ring-swagger (1)
- # specter (9)
- # unrepl (11)
hello everybody, is there a way to get the namespace of a map with uniformly namespaced keys?
e.g. (map-ns {:some/key :val :some/other :val ,,,}) ;; => “some”)
the bot is kind of weird, the original hash-map was {::a 0 ::b 1 ::c 2}
can anyone let me know why this doesnt work
(defn what-is [x]
(cond
(identical? x 42) "everything"
(identical? x (* 42 42)) "everything squared"
:else "nothing"))
(what-is (* 42 42)) ; "nothing"
+user=> (identical? 127 127)
true
+user=> (identical? 128 128)
false
there's a cache for the Longs, but only between -128 and 127, they aren't all cached
identical? isn't just an equality check, it checks if the data is stored in the same location on hardware
when you type in 127, clojure asks for an instance of Long, and java uses a cached set of Longs to look up the value, when you type in 128 clojure once again asks for a Long, but this time java makes a new one
Thanks a lot, i was using the wrong function. This worked
(defn what-is [x]
(cond
(= x 42) "everything"
(= x (* 42 42)) "everything squared"
:else "nothing"))
there's also ==
for numeric equality
eg. it would match 42.0 but = will not
Thank you for the help
@jahson @noisesmith thank you, i was looking for something preferably in core that behaves kind of like namespace
does, returning the namespace when all keys have the same, nil
when not all keys are namespaced, and a set of namespaces when multiple. i’ll write my own then 🙂
returning a set or a string from one function is probably less than ideal - that kind of thing tends to increase the complexity of everything around it for no benefit
you are correct, although it’s just for display purposes in a cli statement, so … 😉