Looking at the documentation for keywords 
under https://clojure.org/reference/reader#_literals
there is no mention for the syntax for namespace aliased keywords, and this 
is very important it you want to manage your keywords for clojure.spec.

I only know about it because google turned up some clojure.spec notes on 
it, but it seems it should be in the mainline clojure docs too.
I certainly didn't know about it until today.

Say we have this namespace:

(ns foo 
  (:require [clojure.spec :as s]))
(s/def ::specific-even-number #(= 1000 %))




And then in the user namespace:

(ns user)
(require '[clojure.spec :as s])
(require '[foo :as f])


(s/valid? :f/specific-even-number 1000) 
;; Exception Unable to resolve spec: :f/specific-even-number  clojure.spec/
reg-resolve! (spec.clj:70)

What is needed is the extra colon, as if we're saying use the current 
namespace, only that isn't what happens.
(s/valid? ::f/specific-even-number 1000)
;; true

Perhaps the clojure docs are correctly stating the use of this kind of 
keyword my interpretation is just flawed, but it certainly wasn't obvious 
to me, and nobody in my team knew that we could do this either.  The result 
was some namespace unfriendly code to avoid typing in long namespaces on 
clojure spec keywords.  Now that we know ::ns-alias/keyword we can do 
better on our clojure.spec use.

(The above tested in clojure 1.8.0).

While I'm here, I want to say that I am _deeply_ disappointed that 
clojure.spec def/fdef forms don't support documentation strings.  I upvoted 
the issue in the bug tracker, but there were only 27 votes including mine 
when I checked on this half-year-plus old issue.
http://dev.clojure.org/jira/browse/CLJ-1965


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to