This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-26
Channels
- # announcements (6)
- # beginners (69)
- # calva (10)
- # clj-kondo (9)
- # clojure (32)
- # clojure-uk (9)
- # clojuredesign-podcast (13)
- # clojurescript (14)
- # clojureverse-ops (2)
- # conjure (24)
- # cursive (12)
- # data-science (1)
- # datomic (13)
- # graalvm (5)
- # jobs-discuss (4)
- # malli (6)
- # meander (33)
- # off-topic (9)
- # pedestal (2)
- # re-frame (38)
- # reitit (6)
- # rum (4)
- # shadow-cljs (6)
- # tools-deps (8)
- # xtdb (26)
So great, @nate!!! And I used my first juxt
last week — felt great, even though I ended up deleting it, because that whole section of code was wrong-headed!
@nate: Just curious, because I’m running into this right now, and you’ve mentioned it in your podcasts — is there an easy way to tell if a keyword is namespaced? :events/reset-card
vs. ::reset/card
.
Is there a better way than converting to string, and looking at first character? Seems… unexpectedly hacky. Thx!!!
@genekim To detect the namespace at all, you can use the namespace
function. It returns nil
if there is no namespace. Eg. (when (namespace ::reset/card) :found-namespace)
.
The ::
syntax is just shorthand for referencing a namespace. It's expanded by the reader. ::
by itself is the "current" namespace. Eg.
user=> ::stuff
:user/stuff
And for something you've required:
user=> (require '[clojure.set :as set])
nil
user=> ::set/difference
:clojure.set/difference
As far as I know, you can't really tell if a namespace was created with the shorthand ::
or not.
user=> (= ::set/difference :clojure.set/difference)
true
user=> (identical? ::set/difference :clojure.set/difference)
true
Symbols are "interned", so identical values will be set to point to the single (immutable) value in memory, so the references will be identical if the value is equal.
I really wish namespace
would give you the keyword for the namespace instead of a string. But you can always convert it if you want the benefits:
(some-> some-keyword-value namespace keyword)
eg.
user=> (some-> ::set/difference namespace keyword)
:clojure.set
user=> (some-> :difference namespace keyword)
nil