--
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 the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
(s/conform (s/coll-of number? #{} #{5 10 2}))
;; should be(s/conform (s/coll-of number? #{}) #{5 10 2})
(s/explain ::game ...)
At: [::players 0 ::hand 0 1] val: :banana fails spec: ::card predicate: suit?
;; but the real output is this, indices from regex matches missing
At: [::players ::hand 1] val: :banana fails spec: ::card predicate: suit?
Spec usage guide questions:
There is a small typo in the 'Collections' section (pretend this is a question):(s/conform (s/coll-of number? #{} #{5 10 2}))
;; should be(s/conform (s/coll-of number? #{}) #{5 10 2})
Is there a technical reason why the paths reported by 's/explain' for regex ops are incomplete? E.g., in the "A game of cards" section, I would expect:(s/explain ::game ...)
At: [::players 0 ::hand 0 1] val: :banana fails spec: ::card predicate: suit?
;; but the real output is this, indices from regex matches missing
At: [::players ::hand 1] val: :banana fails spec: ::card predicate: suit?
It's fine here, but it could get harder to find the failure point in a larger data structure.
Is there a way to write a map spec that contains only the required keyset? This is against the spirit of the 'composition' arguments in the Rationale, but sometimes I really want to pin down the exact data in a map, especially for data about to escape into the wild (e.g. return values of a web API).
The behavior of 's/and' really surprised me (again, pretend this is a question). The conformed values propagating through is semantically weird when you have 'core/and' in mind. Also, if you have data keywords and spec keywords, it could get complicated to keep track of what's what in the later specs. More examples in the "Composing predicates" section, right when 's/and' in introduced, might take away the surprise and replace it with luxurious comfort.
Is there a recommended way to introspect specs for our own purposes (coercion, code generation)? An interpreter on the output of 'describe' might work (although it's a little complicated for fn specs), but I wanted to know if you all had any thoughts or plans for the future here.
We have 1.9.0 Alpha 1 in QA at World Singles and plan to start using clojure.spec this week. We’ve gone to production on Alpha builds ever since 1.3 and almost never had any problems (in five years – time has flown past!).
What sort of tradeoffs have you in mind regarding whether to use clojure.spec or not? I ask because I’m thinking about adding an optional namespace to clojure.java.jdbc that would provide fn-specs for that library – my assumption is that folks not yet using a 1.9.0 build would simply not require that spec namespace…
Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
The paths refer to tags in the schemas, not keys in the map. However, this has been asked about several times today and Rich has added support for a :in clause that will track the key paths to master and that will be in alpha2.
Is there a recommended way to introspect specs for our own purposes (coercion, code generation)? An interpreter on the output of 'describe' might work (although it's a little complicated for fn specs), but I wanted to know if you all had any thoughts or plans for the future here.
Could you give more details on what question you would like to ask?
--
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 the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I would like to see function in the spec namespace that returns true if input conforms to a spec, otherwise returns false and prints to standard out an explanation of the failure. Sort of a valid-or-explain predicate (but a shorter name would be better).
Bear in mind that you can catch the exception thrown by a pre-/post-condition so printing to stdout is not the right behavior.
Are you thinking about something like this?
(when-not (s/valid? spec arg)
(throw (AssertionError. (with-out-str (s/explain spec arg))
(ex-info “SpecFailure” (s/explain-data spec arg)))))
--
Bear in mind that you can catch the exception thrown by a pre-/post-condition so printing to stdout is not the right behavior.
Are you thinking about something like this?
(when-not (s/valid? spec arg)
(throw (AssertionError. (with-out-str (s/explain spec arg))
(ex-info “SpecFailure” (s/explain-data spec arg)))))
We have 1.9.0 Alpha 1 in QA at World Singles and plan to start using clojure.spec this week. We’ve gone to production on Alpha builds ever since 1.3 and almost never had any problems (in five years – time has flown past!).
What sort of tradeoffs have you in mind regarding whether to use clojure.spec or not? I ask because I’m thinking about adding an optional namespace to clojure.java.jdbc that would provide fn-specs for that library – my assumption is that folks not yet using a 1.9.0 build would simply not require that spec namespace…
Hi, Alex, thanks for the responsiveness.The paths refer to tags in the schemas, not keys in the map. However, this has been asked about several times today and Rich has added support for a :in clause that will track the key paths to master and that will be in alpha2.
Where is this discussion thread? I wouldn't want to ask duplicate questions.
Is there a recommended way to introspect specs for our own purposes (coercion, code generation)? An interpreter on the output of 'describe' might work (although it's a little complicated for fn specs), but I wanted to know if you all had any thoughts or plans for the future here.Could you give more details on what question you would like to ask?
Better people to ask would be those that have a lot of experience writing translators for specs, like the Schema devs. But I'll give my muddled thoughts here:
Right now, the internals of different instances of Spec are private. So, to write a translator from a Spec to the approximate json or avro schema it specifies, or translate from a Spec to a function that coerces a String to a data structure that conforms, I would have to:
1. Parse the output of 'describe' back into a description of the Spec's internals (if I can get at all of them)
2. Interpret / translate the parsed tree
In fact, the current Spec protocol, in my mind, is actually 4 protocols, one for 4 different translators you all have written:
(defprotocol Spec
;; Spec->Conformer
(conform* [spec x])
:: Spec->Explainer
(explain* [spec path via x])
;; Spec->Gen
(gen* [spec overrides path rmap])
(with-gen* [spec gfn])
;; Spec->Describer
(describe* [spec]))
But this implementation hiding dooms clojure/core to write all the translators. This just seems weird given how most other Clojure features are open and user-extensible.
--Leif
--
--
I meant more that a failed pre-/post-condition throws AssertionError rather than printing to the console and that a failure using clojure.spec should still do the same thing.
The valid-or-explain function suggested would “work” in terms of being a predicate but the AssertionError wouldn’t reflect the actual details of the failure and you’re assuming stdout is easily accessible.
I think it would be better if the spec-based predicate failed by throwing an exception with the explanation in it (but I haven’t tested how it would actually interact with the pre-/post-condition machinery).
Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
So something like(defn valid-or-explain [spec data](let [v (s/valid? spec data)](when-not v (s/explain spec data))v))
Is there a recommended way to introspect specs for our own purposes (coercion, code generation)? An interpreter on the output of 'describe' might work (although it's a little complicated for fn specs), but I wanted to know if you all had any thoughts or plans for the future here.Could you give more details on what question you would like to ask?
Better people to ask would be those that have a lot of experience writing translators for specs, like the Schema devs. But I'll give my muddled thoughts here:
Right now, the internals of different instances of Spec are private. So, to write a translator from a Spec to the approximate json or avro schema it specifies, or translate from a Spec to a function that coerces a String to a data structure that conforms, I would have to:
1. Parse the output of 'describe' back into a description of the Spec's internals (if I can get at all of them)I'm not sure why you need the internals - the vocabulary of spec is relatively small (+ the open-ended world of predicates). It doesn't seem possible to translate open-ended predicates to fixed types in json or avro, but you could look for known predicates.
I always really liked that Prismatic Schema had a "data representation" and that seems to be the Clojure-way anyways. I haven't dug into this too much yet, but I'm hoping that the Spec's do have some way to programmatically inspect them and utilize their structures for other purposes.
Would it be reasonable to release something for 1.8 which contains all the spec vars but no-ops them?