This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-19
Channels
- # aws-lambda (1)
- # beginners (35)
- # cider (7)
- # cljsjs (2)
- # clojure (48)
- # clojure-austria (1)
- # clojure-conj (9)
- # clojure-dev (8)
- # clojure-india (6)
- # clojure-italy (12)
- # clojure-nl (8)
- # clojure-norway (3)
- # clojure-spec (9)
- # clojure-uk (92)
- # clojurescript (103)
- # community-development (7)
- # cursive (15)
- # datomic (75)
- # devcards (3)
- # emacs (3)
- # events (1)
- # fulcro (129)
- # hoplon (4)
- # immutant (2)
- # jobs (10)
- # leiningen (9)
- # off-topic (4)
- # onyx (2)
- # re-frame (45)
- # reagent (39)
- # reitit (40)
- # remote-jobs (4)
- # ring (2)
- # ring-swagger (9)
- # shadow-cljs (17)
- # tools-deps (31)
So I have a function and a spec that is failing orchestration like so:
(s/def ::my-vector (s/coll-of string? :kind vector))
(s/fdef bool-intersect?
:args (s/and ::my-vector ::my-vector)
:ret boolean?)
(defn bool-intersect?
[vec-one vec-two]
(let [set-one (set vec-one)
set-two (set vec-two)]
(intersection set-one set-two)))
(st/instrument)
(assert (bool-intersect? ["boys" "girls"] ["dads" "moms"]))
ExceptionInfo Call to #'advocado.core/bool-intersect? did not conform to spec:
In: [0] val: ["boys" "girls"] fails spec: :advocado.core/my-vector at: [:args] predicate: string?
In: [1] val: ["dads" "moms"] fails spec: :advocado.core/my-vector at: [:args] predicate: string?
(s/fdef bool-intersect?
:args (s/and ::my-vector ::my-vector)
:ret boolean?)
:args should be (s/cat :vec-one ::my-vector :vec-two ::my-vector)
I think@urbanslug As @hello254 said your spec has an incorrect :args
predicate. You pretty much always want s/cat
for :args
with a name and a spec for each argument.
(s/and ::my-vector ::my-vector)
is pretty much equivalent to just ::my-vector
-- a single vector of strings. You're saying the entire arguments list should be a vector of strings and it should also be a vector of strings.
If you called (bool-intersect? "boys" "girls")
that would probably satisfy your spec...
(and (set "boys")
would create a set of the letters \b \o \y \s
)
Here's a question: Say I have a spec and code in core.clj and a different constants file that contains some maps that I plan to use as test data. Should the symbols/keys in the test data be namespaced to show that they come from the spec. Here's an example:
The spec itself determines whether the the map keys should be namespaced or not: (s/keys :req-un [...])
for a map with unqualified keys; (s/keys :req [...])
for a map with qualified keys (that will match the namespaces in the spec).
(s/def ::person (s/keys ::req [::name ::height]))
(s/fdef is-tall?
:args (s/cat :hooman ::person)
:ret boolean?)
(defn is-tall?
[hooman]
(> 5 (:height hooman)))
With :req-un
, the keys in the map are unqualified. The namespaces used in the spec are just to identify the specs for the keys.
In your code, your ::person
spec states that the keys are namespace-qualified.
That doesn't satisfy the spec.
would it be better not to namespace qualify the keys in the spec then or namespace qualify in the constants?
It's up to you. You can write the spec for either approach.
So an example like
(def example-person
{:source-namespace/name "alice"
:source-namespace/height 7})
Also, the qualifiers used in specs don't actually need to match code namespaces -- if that makes your code more readable (and the qualifier is "unique enough" for your app).
So {:person/name "alice" :person/height 7}
might be a reasonable way to write your data.
And then your spec would be (s/def ::person (s/keys :req [:person/name :person/height]))
The qualifier for ::person
-- the namespace it is defined in -- doesn't have to match the qualifier in the keys.
I'd like to have clojure on golang, specifically these two and preserving their strengths. How do I even start? :)
one gotcha that many attempts to port Clojure run into is that normal Clojure code performs poorly without a high quality garbage collector. Last I heard Go didn't have a great gc, so that will likely be an issue.
Has anyone written or used a Github Bot that runs cljfmt fix
on your project? That would be super handy
@alexmiller So I used (s/or)
without parameters by accident and got some confusing results regarding valid?
and explain
. Is this a bug or am I missing something?
Here an example.
(s/valid? (s/or) :something)
=> false
(s/explain (s/or) :something)
Success!
=> nil
Feel free to file a ticket
I’d say the valid? answer is right and the explain answer is the bug
valid doesn't correct handle predicates so it fails. explain correctly handles predicates so it explains success
I think you’re confusing the issue
That ticket is about s/every which is not relevant here
This is about the explain of s/or
(s/valid? (fn [x] (s/or)) :something) true
vs (s/valid? (s/or) :something) false
I think is an example of it
Well if you find it, put it on the ticket