Namespace question and request for project with non-trivial use of clojure.spec

104 views
Skip to first unread message

Jonathon McKitrick

unread,
Dec 16, 2016, 11:59:50 AM12/16/16
to Clojure
I've run into some odd namespace issues with clojure.spec, and I'm sure it's because I'm doing something wrong. I have this in my ns declaration:

[foo.schema :as schema]

However:

foo.main> (s/valid? :foo.schema/email "f...@bar.com")
true
foo.main> (s/valid? :schema/email "f...@bar.com")
Exception Unable to resolve spec: :schema/email  clojure.spec/reg-resolve! (spec.clj:68)
foo.main>

It would also be useful if I knew of a non-trival project I could view that uses clojure.spec across namespaces, but without being SO complex that the basics are obscured.

Does anyone know of or have an example?

Alex Miller

unread,
Dec 16, 2016, 12:29:03 PM12/16/16
to Clojure


On Friday, December 16, 2016 at 10:59:50 AM UTC-6, Jonathon McKitrick wrote:
I've run into some odd namespace issues with clojure.spec, and I'm sure it's because I'm doing something wrong. I have this in my ns declaration:

[foo.schema :as schema]

However:

foo.main> (s/valid? :foo.schema/email "f...@bar.com")
true
foo.main> (s/valid? :schema/email "f...@bar.com")

You want an auto-resolved keyword here to take advantage of the alias:  ::schema/email. Single colon will just be the literal namespace you write.

jmcki...@gmail.com

unread,
Dec 16, 2016, 1:48:34 PM12/16/16
to Clojure
That did the trick. Thanks!

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@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 a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/mmcMQEhI5Dc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Jonathon McKitrick

Josh Tilles

unread,
Dec 16, 2016, 2:00:31 PM12/16/16
to Clojure
Although I can’t recall off the top of my head any example applications that demo non-trivial spec usage, you might be able to find some good projects using CrossClj: https://crossclj.info/ns/org.clojure/clojure/1.9.0-alpha14/project.clj.html#used. (There’s a good chance that any project that’s using one of the alpha releases of Clojure 1.9 is doing so for spec.)
Reply all
Reply to author
Forward
0 new messages