This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-12
Channels
- # admin-announcements (1)
- # bangalore-clj (13)
- # beginners (149)
- # boot (123)
- # cider (7)
- # clojure (167)
- # clojure-brasil (3)
- # clojure-greece (1)
- # clojure-korea (2)
- # clojure-new-zealand (2)
- # clojure-russia (70)
- # clojure-sanfrancisco (3)
- # clojure-spec (84)
- # clojure-uk (36)
- # clojurescript (300)
- # code-reviews (242)
- # community-development (34)
- # core-async (4)
- # css (1)
- # cursive (37)
- # datascript (1)
- # datomic (20)
- # defnpodcast (1)
- # dirac (15)
- # events (7)
- # garden (12)
- # hoplon (100)
- # lein-figwheel (11)
- # off-topic (2)
- # om (69)
- # om-next (3)
- # onyx (86)
- # planck (14)
- # proton (4)
- # protorepl (1)
- # quil (2)
- # re-frame (53)
- # rum (3)
- # untangled (1)
- # vim (50)
Oh whoops. Instrument just for args, duh. Lazy speed reading of slack posts is never a good idea :-(
Any patterns to avoid things like this
(s/def ::dimensions/seq (s/cat ::dimensions/x ::dimensions/x ::dimensions/y ::dimensions/y ::dimensions/z ::dimensions/z))
@alexisvincent You could use s/tuple
instead - or are you interested in the conforming behavior of s/cat
?
Then I think your only option to avoid the redundancy is to write a macro around s/cat
->
(defn make-dimensions [& d]
(s/conform ::dimensions/seq d))
hmm. was wondering if there was something like the destructureing {:keys []}
So you want to conform your sequential input into a map, right?
yep š
Ah, how about s/keys*
I think that's what you're looking for
Well no, it's not, sorry š
That would require the keys themselves to be present in the input sequence, too
So yeah, you'll have to roll your own wrapper macro
@dergutemoritz Thanks š I wonder though if tuple is not what I want actually
@alexisvincent YW! Yeah, s/tuple
would get rid of the redundancy but it wouldn't conform into a map
But perhaps you can live with that
Oh right.
I wonder if s/keys
maintains order?
Because then I could write a function that first accepts req keys and then optional keys
in order
FWIW, here's a wrapper macro of the kind I'm talking about:
(defmacro keys-cat [& keys] `(s/cat ~@(interleave keys keys)))
(s/conform (keys-cat ::foo ::bar) [1 2]) => #:user{:foo 1, :bar 2}
Or maybe keys-tuple
would be a more fitting name
@dergutemoritz Thanks š
maybe cat-keys
https://s-media-cache-ak0.pinimg.com/originals/c1/19/8f/c1198f0990a37c100437b8c31309c4e8.jpg
is the general consensus to prefer namespaced keys in maps?
Are people generally using ::
as a helper
Its a pain when wanting to use the spec in another nsā¦ You have to specify the full mylonglongname.namespace.thing/name
becomes so long windedā¦
Or are people just registering thing/name
OH š ::
can also be used for aliasing
What is the best way of namespacing an existing map? Using a function, not the reader
@dm3 yep š
@alqvist what do you mean? adding a namespace to the keys of a map?
there is no function to do that right now
@alexmiller exactly that - I made a small function for it. Posted it in #clojure
Is there some preferred way of writing simulation-testable specs for functions with constraints between parameters? I have a function that takes a map and a key. The key must exist in the map for both the input and output. I can make it work by writing a custom generator for :args
using bind
, was wondering if there was a preferred method.
that is the preferred method
^^ is about that
Thanks, that's basically how I handled it.
I notice in the video that the generator override was specified directly in the test, rather than in the spec. Don't know that it makes much difference, though giving it in the spec would allow you to reuse the override if that spec was composed with others.
is there a spec or predicate for objects that have strict value equality? looking for something like a clojure.core/edn?
or something like that
edn? isnāt quite right, since thatās about serializability, but would be close enough for my needs
i have a procedure that will go in to an infinite loop if the function isnāt pure & iāve been bitten a few times by including a function in it
the generator for any? was way simpler than preferred last time I checked, there was a bug on test.check about it
which i guess i could make, but it seemed like it might have been something that existed or should exist
I think there are some things in test-check with "printable" in their name?
I know we spent a lot of time building up stuff like that in the old data.generative
Certainly open to ideas
alexmiller: this looks more or less like what i need. would be cool to have a predicate for it
Jira it up
Seems like we could also fix test.check re NaN (which is not currently printable)
i think clojure.core/edn?
would be the least objectionable formulation of this request
I think it's probably unlikely we would make that predicate
yeah - after realizing it was O(N), i realized that - but a spec makes more sense, right?
Well, definitely a generator, maybe a spec
besides the stuff in clojure.core.specs, are there any āstandardā specs anywhere? i donāt think so, right? just predicates...
In this example from the spec guide, is the ability to key into the arguments with :start and :end created by the s/cat above the anon function? Does the destructuring happen such that the first expression given to s/and has an effect on whatās passed to the other?
(s/fdef ranged-rand
:args (s/and (s/cat :start int? :end int?)
#(< (:start %) (:end %)))
ā¦
@jeremyraines yes, the s/cat conforms the data. s/and threads the conformed data
ok, thanks