Fork me on GitHub

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.


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?


(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


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.


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


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


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


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:


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


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

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


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

💯 4
🙌 3

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


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.


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


Cool, Thank you!


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


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

👍 17

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

Banks are fragile..


They lend and borrow money


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

💯 1

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


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


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%


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.


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

parrot 1
👏 2

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


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


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


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


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

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

✔️ 7

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!


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

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


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


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


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


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


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?


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?


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


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


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


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


Annoying, it seems like

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


Maybe it wasn't implemented for macOS or something


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


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


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


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?


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


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


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


you might consider transit, which unlike edn is designed for communication between processes

✔️ 1

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