This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-13
Channels
- # announcements (2)
- # babashka (2)
- # beginners (112)
- # calva (29)
- # cider (33)
- # clj-kondo (41)
- # cljdoc (10)
- # cljs-dev (2)
- # clojure (72)
- # clojure-berlin (3)
- # clojure-europe (10)
- # clojure-italy (6)
- # clojure-nl (15)
- # clojure-spec (5)
- # clojure-uk (40)
- # clojurescript (1)
- # clr (6)
- # community-development (6)
- # core-async (21)
- # cursive (42)
- # datascript (12)
- # duct (6)
- # flambo (1)
- # fulcro (50)
- # jobs (1)
- # leiningen (3)
- # off-topic (16)
- # re-frame (6)
- # reagent (23)
- # reitit (7)
- # ring-swagger (14)
- # shadow-cljs (35)
- # tools-deps (39)
- # vim (12)
What are symbol
and first
bound to in that code?
Also should $gte
be :$gte
?
The document in the db is like this { :symbol "abc" :series [ {:date 2019-01-01 :data 1} {:date 2019-01-02 :data 2} }]
Hmm, I don't see anything obvious. You have :$lte
there but $gte
in your previous example. I would recommend not shadowing core functions in function arguments in general tho' just to eliminate potential problems down the road...
There's a #mongo channel which might have some Monger users...
@seancorfield thanks!
howdy. What's up?
hacking on a bit of Clojure code for hobby, and keeping up with the hubbub.
What is the currently recommended way of clojure.test
ing fdef
’d functions? This test.check method seems closest to a builtin solution, but I can’t quite figure out how to make it work with spec: https://clojure.org/guides/test_check_beginner#_defspec
I’ve read through https://clojureverse.org/t/integrate-functions-specs-fdef-and-clojure-test/1448/3, which seems to suggest that there isn’t an out of the box solution yet. Is that true?
Is this my best bet? https://stackoverflow.com/a/55839670/419043
@jake I think that's the same question I answered here just the other day https://ask.clojure.org/index.php/8590/clojure-spec-alpha-check-inside-clojure-testing-framework
(It's a different approach to the SO answer -- it's based on what we do at work)
The answer on ClojureVerse looks like a good approach as well.
(the approach on SO seems overly complicated to me)
I imagine a builtin solution might help drive spec/check adoption - that would be cool to see some day
Well, check
isn't really intended to be run as part of "unit tests".
Those should be very fast and get run "all the time". Generative testing, such as check
, often is not very fast and is generally run out of band, either manually or just with a separate script that you run "sometimes" -- such as perhaps a full sweep of test suites as part of CI/CD.
So you don't need integration with clojure.test
per se for that.
We only have one check
call executed as part of our entire test suite (about 20k lines of Clojure -- our production code is about 70k lines). We have a few Rich Comment Forms with calls to check
I think, for manual testing.
Similarly, we only have a handful of property-based tests in our unit tests (that use test.check's
defspec
-- which confusingly predates clojure.spec
). But we have some RCFs containing deeper property-based tests.
this is helpful info. We’re definitely still trying to get a good feel for how best to leverage and assemble the various pieces of the spec / check / test ecosystem
it’s all just different enough from other tools that we’ve used that sometimes it can be hard to tell which way is up, haha
We use Spec primarily in production code, to validate/conform data. We have instrument
ation in place in a few places during dev/test.
My advice is to Spec at the boundaries of subsystems and/or on critical functions but do not treat it like a type system.
More details here https://www.quora.com/If-you-use-Clojure-Spec-how-do-you-use-it-Do-you-tend-to-put-all-your-specs-in-one-place-or-distribute-them-through-the-modules-of-your-program/answer/Sean-Corfield?srid=upNN if you have a Quora account.
I probably ought to transcribe that onto my blog so non-Quorans can read it...
@deadghost You may still be going crazy but, yes, it does throw an exception 🙂
For folks without a Quora account https://corfield.org/blog/2019/09/13/using-spec/
(conj (sorted-set-by
(comp < :rank)
{:spec ::spec
:rank 1})
{:spec ::spec
:rank 1})
=>
#{{:spec :den1k.defmostly/spec, :rank 1}
{:spec :den1k.defmostly/spec, :rank 1}}
^ it looks like the comparator is breaking hashing? For my use case I'm looking for a set of maps sorted in descending order by the :rank
key. How could I achieve that?
The function created by comp there is being invoked on each thing, and the result compared
It might only protect against weird corner cases that you will never see in your data, but I would even suggest the more verbose (fn [a b] (compare (:rank b) (:rank a)))
, for reasons described in this article about very subtle dangers of using subtraction/negation in comparators: https://clojure.org/guides/comparators
that is very interesting, I hadn't see that guide before, but I am pretty sure the subtraction being cautioned against there is different from the negation of values to reverse the sort I am suggesting
sort-set-by takes a function that is applied to each item in the set and then the items are sorted by the result of that function
that guide is caution against writing a function of two arguments (which is actually used for comparing) that subtracts one of the arguments from another
Right. Again, this is really really corner case stuff, but for example (- Long/MIN_VALUE)
throws an exception.
which is not mentioned in that guide, but is related to some of the reasons why -
is recommended against in that article.
2^64-1
times out of 2^64
it doesn't matter 🙂
Oh, and of course my suggested function doesn't apply for sort-by
, only as an alternate comparison function for sort
If anyone is curious: I've setup a simple testing workflow using github actions and tools-deps: https://github.com/cljfx/cljfx/blob/master/.github/workflows/test.yml
Very neat! I wonder how TravisCI and CircleCI will be affected by GitHub Actions/Workflows? Maybe they'll enjoy have less FOSS load on their servers? 🙂
(I just registered for the Actions Beta -- how long did it take you to get an approval @U47G49KHQ?)
@seancorfield I'll ping someone, you can generally be fast-tracked under the "prolific OSS developer" hat.
@U05509S91 Much appreciated sir!
somehow in my mind the value space for negative and positive must be symmetrical, but that isn't the case for twos complement of course