Fork me on GitHub
#clojure
<
2019-09-13
>
seancorfield00:09:30

What are symbol and first bound to in that code?

seancorfield00:09:59

Also should $gte be :$gte?

awb9900:09:16

symbol = "abc"

awb9900:09:29

first = (t/now)

awb9900:09:58

The document in the db is like this { :symbol "abc" :series [ {:date 2019-01-01 :data 1} {:date 2019-01-02 :data 2} }]

awb9900:09:16

the series array can contain tens of thousands of entries,

awb9900:09:23

so I want to filter it in the database.

seancorfield00:09:29

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...

👍 4
seancorfield00:09:12

There's a #mongo channel which might have some Monger users...

Victor04:09:43

hello

👋 8
andy.fingerhut04:09:58

howdy. What's up?

Victor04:09:22

not much, just checking out cool corners of the web. hbu?

andy.fingerhut04:09:41

hacking on a bit of Clojure code for hobby, and keeping up with the hubbub.

Victor04:09:24

cool, what hobby?

Victor04:09:14

or wait, code is the hobby. oops

Victor04:09:21

gotta run, but I’ll be back!

telekid17:09:11

What is the currently recommended way of clojure.testing 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

seancorfield18:09:09

(It's a different approach to the SO answer -- it's based on what we do at work)

seancorfield18:09:10

The answer on ClojureVerse looks like a good approach as well.

telekid18:09:44

Amazing, thank you. This is very helpful.

seancorfield18:09:53

(the approach on SO seems overly complicated to me)

telekid18:09:52

I imagine a builtin solution might help drive spec/check adoption - that would be cool to see some day

seancorfield18:09:10

Well, check isn't really intended to be run as part of "unit tests".

seancorfield18:09:55

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.

seancorfield18:09:24

So you don't need integration with clojure.test per se for that.

telekid18:09:48

ah, that makes sense

seancorfield18:09:30

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.

seancorfield18:09:47

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.

telekid18:09:10

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

telekid18:09:12

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

seancorfield18:09:22

We use Spec primarily in production code, to validate/conform data. We have instrumentation in place in a few places during dev/test.

seancorfield18:09:17

My advice is to Spec at the boundaries of subsystems and/or on critical functions but do not treat it like a type system.

telekid18:09:51

that seems like good advice!

seancorfield18:09:05

I probably ought to transcribe that onto my blog so non-Quorans can read it...

deadghost18:09:11

Am I going crazy or does (clojure.edn/read-string "123abc") throw an Exception

deadghost18:09:03

oh I see has to be double quoted

seancorfield18:09:09

@deadghost You may still be going crazy but, yes, it does throw an exception 🙂

😂 4
denik19:09:36

(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}}

denik19:09:19

^ 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?

hiredman19:09:21

A comparator must be a total order

hiredman19:09:26

And that isn't even how a comparator is passed in

hiredman19:09:00

The function created by comp there is being invoked on each thing, and the result compared

hiredman19:09:23

What you want is (comp - :rank)

andy.fingerhut19:09:25

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

hiredman20:09:27

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

hiredman20:09:56

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

hiredman20:09:11

the function passed in is not the comparing function

hiredman20:09:41

it is a function used to derive the value that is then used for comparison

hiredman20:09:49

so it is a function of a single argument

hiredman20:09:32

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

andy.fingerhut20:09:00

Right. Again, this is really really corner case stuff, but for example (- Long/MIN_VALUE) throws an exception.

andy.fingerhut20:09:41

which is not mentioned in that guide, but is related to some of the reasons why - is recommended against in that article.

andy.fingerhut20:09:14

2^64-1 times out of 2^64 it doesn't matter 🙂

andy.fingerhut20:09:03

Oh, and of course my suggested function doesn't apply for sort-by, only as an alternate comparison function for sort

hiredman20:09:24

I guess there is always -'

🙃 4
vlaaad20:09:41

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

seancorfield20:09:36

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? 🙂

seancorfield20:09:02

(I just registered for the Actions Beta -- how long did it take you to get an approval @U47G49KHQ?)

vlaaad20:09:23

I think about a week or so

gerred20:09:23

@seancorfield I'll ping someone, you can generally be fast-tracked under the "prolific OSS developer" hat.

😊 4
seancorfield20:09:03

@U05509S91 Much appreciated sir!

hiredman20:09:13

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

emccue22:09:17

Curious - what exactly happens under the hood if you extend a protocol onto another protocol

hiredman23:09:15

if you screw up and import the interface generated by defprotocol instead of requiring the protocol, then you are in the realm of undefined the behavior and will get all kinds of things happening depending on exactly how you use the protocol and the interface after that point