Fork me on GitHub
#clojure
<
2020-07-23
>
Gabriel04:07:01

Hello, is there a function that can check if two values are equal but supports accretion? For example:

(is-equal {:first-name "David" :middle-name "Robert" :last-name "Jones"} {first-name "David" :last-name "Jones"})
;=> true
(is-equal {:first-name "Duncan" :last-name "Jones"} {first-name "David" :last-name "Jones"})
;=> false 
I know that this isn't really equality, but I don't know how to express this. I'm writing tests and I want to perform assertions over the data that I pass to a function and I don't like having to correct tests just because my code now passes an extra key that isn't expected at all.

phronmophobic04:07:33

what are the semantics? • true when :first-name and :last-name values match • true if the keys that do exist match • true if the overlapping keys have equal values • true if the keys of one map are a subset of the keys of another and the corresponding values are equal • something else?

phronmophobic04:07:51

(let [keys-i-care-about [:first-name :lastname]]
  (= (select-keys keys-i-care-about
                  {:first-name "David" :middle-name "Robert" :last-name "Jones"})
     (select-keys keys-i-care-about
                  {:first-name "David" :last-name "Jones"}))) 
;; => true

Gabriel04:07:22

Yeah, definitely somthing like that. But I was wondering if there was already something more generalized. I'm writing tests and all my tests have the form (is (= expected actual)) and I feel like = is not really what I need here.

phronmophobic04:07:46

it probably depends on the use case, but based on the example, it seem like you want some sort of identifier

phronmophobic04:07:41

(= (:id first-map)
   (:id second-map))

hiredman05:07:03

I've written a predicate I called submap? (Like subset?) For that kind of thing in the past

solf05:07:36

Not quite what you're looking for, but malli can be used to validate maps, and maps are "open by default" (you can ctrl-f that here: https://github.com/metosin/malli)

seancorfield05:07:00

I think there's a submap? in clojure.spec.alpha but maybe it is private?

solf05:07:39

There's also a subset? in clojure.set, I think this works:

(defn is-equal [actual expected]
  (clojure.set/subset? (set expected) (set actual)))

plexus07:07:13

For tests in particular matcher-combinators are great https://github.com/nubank/matcher-combinators , and allow you to do a lot more stuff like checking if collections have the same contents but disregarding ordering

💯 4
🙌 3
Gabriel13:07:04

Thanks everyone for your input! matcher-combinators and motif have what I was looking for. 😁

Tom Cooper20:07:23

If you know that a has possibly more “stuff” in it than b that you want to ignore, then couldn’t you also just do something like (= a (select-keys b (keys a)) ?

rutledgepaulv01:07:13

of course. but take it to its logical conclusion of "open" / "accretion friendly" testing and you end up wanting some more things like those offered in some of the mentioned libraries.

seancorfield05:07:40

@gabriel857 You might want to look at https://github.com/clojure-expectations/clojure-test/ which has a number of non-equality fancy "comparisons", including an in (submap) test.

Gabriel14:07:20

Cool, Thank you!

lefteris06:07:28

Hello , I'm new here, can anyone give any advice or online material for clojure interview questions?

gerritjvv12:07:57

I think this is good news for the future of Clojure!!.

👍 17
gerritjvv12:07:34

Nubank does not own Clojure, just as Cognitect never owned Clojure. Nubank will take over Cognitect's role as a corporate sponsor for Clojure, funding the core development effort

👍 4
stan13:07:21

Banks are fragile..

stan13:07:28

They lend and borrow money

gerritjvv13:07:32

for all that I like cognitect, compared to banks , dev consultancies are even more fragile.

💯 1
gerritjvv13:07:53

so having bigger money and a bigger player backing the language is good.

gerritjvv13:07:51

also when people look at what lang to learn/use, allot of times who's backing it influences their decision.

stan13:07:57

I am a consultancy. The main problem is when 90% of you income comes from a single source. You become unfit, dependant and yes, fragile. Nubank deal sounds like they will now have 100%

kah0ona19:07:14

That is a pretty glass half-empty way of looking at things. Are they more fragile than before? Is it unrecoverable from if things go wrong? I doubt it, I think it's great for them.

rboyd13:07:40

nice to see it when capital allocation works well and resources make it to the right people. congrats to cognitect! 🍾

parrot 1
👏 2
rickmoynihan14:07:15

My warmest most heartfelt congratulations to all the Cognitecters and their new colleagues at nubank! I wish you all the best, and I feel like this could be a great pivotal moment for clojure and the community; and it couldn’t happen to a more deserving bunch of people. I sincerely hope this is a career highlight for you all, and I’m sure your, indeed our collective futures will be all the brighter for it! My only question which is really a clarification, is does this: > Nubank does not own Clojure, just as Cognitect never owned Clojure. Nubank will take over Cognitect’s role as a corporate sponsor for Clojure, funding the core development effort; specifically mean that Rich has still retained all of the copyrights to clojure? I appreciate this is non of my business really; but as a longtime clojure practitioner it would be reassuring to know in concrete terms that Rich is still legally custodian of the language, beyond it being EPL licensed (which should be reassuring enough to be honest).

dpsutton14:07:14

*   Clojure
 *   Copyright (c) Rich Hickey. All rights reserved.
I thought rich has personally retained copyright even before cognitect

alexmiller14:07:32

and the Clojure Contributor Agreement specifically grants joint copyright to Rich Hickey

rickmoynihan14:07:59

Great. Thanks a million for clarifying, that this hasn’t changed. And congratulations again! Please return to the much deserved celebrations! 😁 🎉 🎊 🎆 🍾 🍵 hammock

borkdude14:07:56

So Cognitect will be absorbed by Nubank, but they will continue to do Datomic consulting. Isn't it a bit weird for a bank to do database consulting? Or will Cognitect be a daughter company of some sorts, with their own brand still

👆 1
alexmiller14:07:32

"Cognitect will continue to operate as a U.S. C Corporation."

✔️ 7
agigao15:07:45

Congratulations regarding the acquisition! Hopefully this will turn out for better for all people behind Clojure and for us - its enthusiasts as well, fingers crossed!

alexmiller15:07:44

It's great news and we're all excited to be part of Nubank!

clj 12
cider 5
clojure-spin 14
🎉 11
😮 4
parrot 7
❤️ 1
lukasz15:07:57

@alexmiller congratulations to the Cognitect team - this is great news 🎉

markbastian15:07:47

I am particularly excited about the mentioned technical, social, and financial contributions. Anything to spread the goodness is welcome. Congrats to the Cognitect team!

blmstrm15:07:28

Hi! Does someone have any recommendations for a library for google cloud storage?

lukasz16:07:38

Disclaimer: While I didn't work with Google's cloud storage - I use their SDKs with other APIs they offer. Based on that, I found that just using their Java SDKs was the best approach: you can adopt examples from their documentation, there's no extra layer between your code and the SDK and lastly, their Java APIs are ok and are not that hard to use from Clojure

blmstrm00:07:52

Great, thanks! I’ll have a look and give it a try. :)

fadrian16:07:14

I'm currently feeling that my namespace-fu is not well developed. Could anyone recommend a good introduction to namespaces, how local and external namespaces are managed, how that relates to the Java runtime environment, and what parts of the ns macro triggers these operations? Or some combination of that sort of documentation?

sandbags16:07:35

I'm puzzling over a profiling issue. I'm using Tufte to profile some code and I'm struggling to work out the discrepancy between the walk-clock time and the time taken in the profiled functions. The outer function times at 7.88s (and it does take about that long) but is just a loop that runs the inner function which times at 162us. Which is itself odd because this function is calling other functions that profile at ~1s clock time. Perhaps I am reading something wrong? Where is the missing 7s of wall-clock time?

lmergen16:07:20

it wouldn’t be the first time I would see very long GC pauses be the explanation for “missing time” in profilers

sandbags16:07:08

That is possible except 7s on a 1s runtime, I wouldn't expect to be creating that much garbage. I can't remember how to turn off the GC but I guess I could figure it out and re-run

lmergen17:07:13

I think your best course of action is to hook an actual java profiler into it and see what’s going on

sandbags17:07:28

Perhaps so, I tried using the Epsilon GC but can’t get it to run

sandbags18:07:23

Annoying, it seems like

:jvm-opts ["-XX:+UnlockExperimentalVMOptions" "-XX:+UseEpsilonGC"]
ought to do the trick but: Unrecognized VM option 'UseEpsilonGC'

sandbags18:07:01

Maybe it wasn't implemented for macOS or something

sandbags08:07:55

Okay I wasn't able to disable the GC but I do seem to be able to log it's activity and it doesn't appear (assuming -verbose:gc tells the whole picture) to be GC pauses

sandbags08:07:37

This would be in line with this code creating a fairly trivial amount of garbage for a 1000 tuple test.

sandbags12:07:33

Ah, I'm still on JDK 8, EpsilonGC is JDK 11. That explains that!

quadron19:07:41

i'm trying to communicate edn through a network. i'm sending edn to an aleph server and have tried different http clients. the problem is that these libs seem to know nothing about edn and I find myself converting edn to bytes and vice versa by hand. am i missing something?

tvaughan14:07:59

Over HTTP? Are you setting Content-Type and Accept on the client request?

quadron19:07:38

aren't clojure libs supposed to implement the edn protocol? :face_with_monocle:

zilti21:07:11

http-clj works fine for me, I usually do it like ( -> (http-clj/get "url here") :body edn/read-string) and am done with it. For my current project I also put {:accept :edn} in the "get" call, because server-side I use muuntaja which is a ring-middleware that converts the data according to the :accept header the client sends

noisesmith19:07:52

you might consider transit, which unlike edn is designed for communication between processes https://github.com/cognitect/transit-clj

✔️ 1
kenny23:07:05

Any idea what is going on here?

(defn test-2
  []
  (loop [x? (pos? 1)
         is (map some? [1 nil 2 nil])]
    (when (not-empty is)
      (recur
        (first is)
        (rest is)))))
Syntax error (IllegalArgumentException) compiling fn* at (env/cs/dev/ws_dev_dash.clj:175:1).
 recur arg for primitive local: x_QMARK_ is not matching primitive, had: Object, needed: boolean