This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-03
Channels
- # bangalore-clj (1)
- # beginners (160)
- # boot (174)
- # cider (57)
- # cljs-dev (16)
- # cljsrn (5)
- # clojure (144)
- # clojure-argentina (1)
- # clojure-austin (6)
- # clojure-finland (2)
- # clojure-france (4)
- # clojure-russia (185)
- # clojure-serbia (4)
- # clojure-spec (61)
- # clojure-uk (126)
- # clojurescript (212)
- # community-development (7)
- # core-async (2)
- # cursive (17)
- # datomic (210)
- # emacs (10)
- # euroclojure (2)
- # gsoc (23)
- # hoplon (86)
- # jobs (8)
- # lein-figwheel (9)
- # luminus (19)
- # lumo (12)
- # off-topic (4)
- # om (14)
- # om-next (6)
- # pedestal (38)
- # perun (11)
- # planck (35)
- # portland-or (2)
- # ring (1)
- # ring-swagger (28)
- # specter (6)
- # untangled (6)
- # yada (2)
finally starting to get a hang of how to use instrument
effectively while doing interactive development via the REPL, :replace
is very handy in isolating parts of a long pipeline of functions that build up the computation step by step
having a version of enumerate-namespace
that recursively enumerates all the internal functions called by some top-level function would be quite handy
@ghadi @joshjones You are correct and I am embarrassed 😄 I think the case at hand may have contributed to the confusion. I was applying specs to a deep, previously unspec:ed map where both spec:ed and unspec:ed keys were present.
i have a spec of form (s/def :foo/bar ...)
where :foo/bar
is used somewhere in the ...
this gives me an Unable to resolve spec
error, what's the recommended way to do such circular definitions in spec?
Oh, I would love to have some sanity brought on to cloudformations json. Love the service but I stumble on the JSON details all the time
How is :foo/bar
used recursively? Doesn't something like:
(s/def :foo/bar (s/keys :opt [:foo/bar]))
(s/valid? :foo/bar {:foo/bar {:foo/bar {}}})
work? Or am I being naive?@chrisblom What @fnil has suggested works for a map. A more fleshed out example:
(s/def ::k string?)
(s/def ::m (s/keys :req [::k] :opt [::m]))
(s/valid? ::m {::k "abc" ::z 42
::m {::k "def"
::m {::k "ghi"}}})
but I don't know if you're spec-ing a map, a collection, or what ? you can also do recursive definitions for collections, etc., but if you can be more specific about the structure you're trying to spec..
Hello. I think that fully namespaced keywords without full application's namespace should be considered as very bad practice (:message/state for example) at least in library code. But why the official guide is full of such usages?
(s/def :event/type keyword?)
(s/def :event/timestamp int?)
(s/def :search/url string?)
(s/def :error/message string?)
(s/def :error/code int?)
I think I agree @prepor. since specs are global I would say that libraries should never use keys outside of the namespaces already in the lib
to prevent clashes with application code and other libs
I think it makes it a tad harder to find the namespace where the s/def
lives. Also, if you're referring to the specs in other namespaces, it's harder to figure out which namespace you need to require in order to have those specs available
@fnil because of @joost-diepenmaat explanation, yes
I’m using single-keyword namespaces in an application right now and it’s very neat. Writing libraries generally means sacrificing some easyness for interoperability
I definitely agree that it can be hard to locate where a certain keyword was defined (or sometimes redefined)
@joost-diepenmaat a boundary between application and library is often not clear. today it's application code, and tomorrow you can decide to split it into libraries to use inside your microservices.
so, personally I decided to not use "short namespaces" at all. and for me it's strange that official guide forces this usage. maybe I don't understand something...
The guide uses ::stuff
in most places tho` which is qualified by the full namespace. I think the other places in the guide are just examples -- certainly not "forcing" any particular usage on you.
The spec guide seems to be aimed at learning how spec works, and as such, brevity and simplicity are key -- adding too much info on namespaces makes it more difficult to learn. ::mykey
is short, and simple ... at any rate, if you want to do something like this, I think it's a good way to shorten the code while still being namespace-safe:
(create-ns 'my.app.events)
(alias 'event 'my.app.events)
(s/def ::event/type keyword?)
@joshjones yes, I know about create-ns / alias
It's a guide not a set of rules. You're reading too much into it.
If anything I'd say the core team don't provide enough guidance. They really don't force their views on anyone.
@seancorfield will you think the same when you catch a bug because two of your dependencies have name conflicts without any warnings because the official guide guided their authors to not always use fully qualified keywords? 🙂
It's near the only way how you can broke others code in clojure ecosystem in non tricky way, I think
When the core team talk about spec, they're pretty clear about using namespaces to prevent exactly that bug. Again, you're treating a learning guide as a rule book. There doesn't seem much point in this discussion if you're set on blaming the core team for your mistakes 😸
hm. wrong tools force me to make my mistakes. is there no chance that core team did something wrong? don't think so. I'm sure that its ok, then somebody asks questions about core team decisions.
I'm trying to find some big real world applications on github which uses core.spec but can't 🙂
One option I have found that can work is using the :full.ns.no.alias/kw
form can help work around circular dependencies.
@prepor We use spec in production fairly heavily — and I know there are other companies already doing so — but of course you won’t find commercial application code on GitHub 🙂
@prepor And remember the saying: “It’s a poor craftsman that blames his tools.” (not sure whether that saying originates but I remember hearing it a lot growing up)
You can do something like:
(s/fdef hello
:args (s/cat (s/? string?))
:ret string?)
(defn hello
([] (hello “world”))
([name] (str “Hello, “ name \!)))
ok... I haven't looked into this much but wondering about doing pattern matching with core.match and spec to be like a guard or something...
@prepor the guide uses shorter names and ::
kws for readability. it would be reasonable to add a side bar explaining this.
@prepor sidebar added https://github.com/clojure/clojure-site/commit/cf0a744c2e59fcd0c6459d55dba429577399e6c0
@alexmiller cool, thank you! the only thing which I imagine to catch (and debug) such errors automatically is "production mode" for clojure.spec which forbids redefinition of specs in explicit way
@chrisblom that sounds like a great project. huge surface area, though
@spieden very cool! I have had such a thought but have not fully grasped cloudformation and its template language yet
yeah for sure. they have their own (hosted) validation operation, but it misses things and works against the JSON representation
Could you help a Newbie: I am going through http://blog.cognitect.com/blog/2016/10/5/interactive-development-with-clojurespec and cannot get past
codebreaker=> (s/exercise (:args (s/get-spec `score)))
FileNotFoundException Could not locate clojure/test/check/generators__init.class or clojure/test/check/generators.clj on classpath. clojure.lang.RT.load (RT.java:458)
I am using Clojure 1.9.0-alpha14 in lein repl