Fork me on GitHub

If I have many (~15) maps that I want to call upon for tests, what's the best way I should go about defining them? It is too much that I wouldn't want to put it in the same file as my tests. Is putting them in a clj file called x_test_data.clj bad practice?


If it's just data you can put them in x_test_data.edn


okay so the problem I have is that if i do that I can't quite run my tests in the repl


because the project im working on uses lein-modules, and typically for dev there is a dev folder to start the repl from


okay maybe let me asking another question :thinking_face:


Is there a clojure function to convert a relative file path to an absolute one?


load it from the classpath using, not directly from the filesystem


any suggestions on what i should do if my classpath is different from where i put my resource?


it isn't a resource if it isn't on the classpath


a hack I can do is to

(require '[cemerick.pomegranate :as pom])
(pom/add-classpath "....")


in general if you put it next to a clojure source file then it will be on the classpath, because clojure source code is loaded as a resource via classloaders


if you have test.clj file you can put your test.edn file right next to it


and not in resources?


usually by convention people don't intermingle their source code and resources


but they are all loaded the same way


you (require ' ultimately the resource "foo/bar.clj" is looked for


right but ideally I don't want to have to intermingle them


some projects will define a separate test-resources folder and setup on their tooling to include that when running tests


yeap I do have that - maybe the context is that i have a project using lein modules aka multiple lein projects in 1 project


I have a project-dev project where I'm expected to start my lein from but the code I want to run is in the project-core project


you know I used to work with the guy who started the lein project, he started it because he hated the maven multi module build we had at work

😂 1

so seeing that re-implemented on top of lein is really something


wow 😅 that i didn't know


once lein got big enough our boss made a massive git change to the repo over the weekend to switch from maven to lein


Meanwhile, I'm unfortunately not in the position to switch my project out of a lein-modules project :x


So I'm trying my best to make repl driven development in that project still good with these limitations i guess


So things have been alright due to the existence of :source-paths in lein


but now slurping in resources for tests in the repl doesn't work


my initial way was to define all my resources in a namespace like recon-test-data but putting all the data into a clj file/ns seems like bad practice


So I'm just trying to see if there's another way I can do it (cause the way of putting it into a ns was something my colleague commented on - wanting me to change it)


Sure, I dunno, I would just mingle it at not worry, especially for tests


Okay! Thanks for your advice! And the interesting bit of history haha


You're swimming in the waters that lead to a monorepo and your life will be better when you get there.


lein-modules is kind of a horrible idea 😞

😶 1

The irony is that it is a monorepo hahaha


but one with lein modules


Oh god, that's even worse then! Switch to deps.edn and the CLI as soon as you can!


I'll try - personally haven't used deps.edn to know how that will work out


We started getting into a mess with Leiningen as our repo grew and we switched to Boot in 2015 and then to the CLI in 2018. Life is so much better!


But I think I probably have to tread wisely as I make sure not to annoy my boss and earn his trust


Ah yeah, you're pretty new at this place, as I recall?


Yeap! Just transferred department and team, and started being a Clojure dev at the start of november


Yeah, you might get resistance trying to move away from "industry standard" Leiningen, unfortunately.


And other things I realise is that I'm the only one really doing repl driven development in a sense - I mean they do use a repl in great ways to inspect a running system


It's a shame because it's really rigid and it's easy to outgrow it, in my opinion.


Ah, yeah, that would mean they're not feeling the pain...


but from my understanding, they type into the repl when they use it so .... :x


Though, my boss introduce someone new (was doing another project in his team) into the same clojure team and have been directing him to the right resources


But I'm in the meanwhile just trying to smoothen the path so that when he starts working on the project there isn't too much difficult in him wanted to do repl driven development


I spent all day today working in our legacy app, rewriting it to Clojure. It runs a Socket REPL. So I started the app, connected my editor to it, and eval'd code into it as I wrote it so the legacy app changes in real time. THAT is RDD.


which i think is most ok - just not for the tests


sometimes I think it is a weird scenario, like my boss went from (from what i understand) repl driven development with emacs+cider, to intellij+cursive (cause his laptop was reformatted and can't install emacs again) and idk if it was a matter of shortcuts or what but he seem to stop doing RDD


I can't imagine ever going back from RDD. That's why I have socket REPLs running in the legacy apps. I can't do without it.


It's how I debug our QA and even our production processes -- via socket REPLs inside live, running apps.


Neither can I. But okay we do have a nrepl running in our application. Which we do use for debugging. Which is great


Tho probably for company security reasons, not something we can easily just connect to in the editor (probably possible but haven't tried setting it up). And just evaluate code from the editor in


Just lein repl :connect ... and typing there


But all in all, am glad to be working with Clojure, just that I have to work around certain constraints and also hopefully gradually earn my boss' trust with time (and not annoy him instead 😅 )


Hopefully, you can work to slowly modernize them and get them to move to a better monorepo setup.


Send them links to my blog 🙂




Will do! 😄


I have a PersistentHashMap and I am doing select-keys on it. It is returning PersistenArryMap

Antonio Bibiano10:12:12

I think it's related to the size of the map, it's an implementation detail but if your map has more than 8 entries it's a PersistentHashMap if has less it's a PersistentArrayMap so i guess if you're selecting less than 8 keys you'll get your behaviour

Dler Osman10:12:33

Please fill out this survey on Covid-19. It takes less than 2 minutes


Deleting this.


Is there a way to list all dependencies and their versions with the clojure cli? (e.g. to find out if log4j is an indirect dep of my project and see all versions used)


clj -X:deps list


Or clj -X:deps tree to see the dependency chain.


Take a look at tools.deps.graph as well if you're looking for something fancier:

Isaac Wooden17:12:12

What's a good function for merge-with to collect scalar values into a list? E.g. (merge-with ?? {:a 3} {:a 4} {:a 5}) -> {:a [3 4 5]} , the usual suspects of into/`conj`/`concat` don't really fit since the values don't start off as collections

Isaac Wooden18:12:40

Well, maybe this isn't a good example since you can just (map :a data) , how about turning something like {:a 1} {:a 2} {:b [3 4]} {:b [5 6]} into {:a [1 2] :b [[3 4] [5 6]]} ?

Sam Ritchie18:12:58

Map-values vector across each side first then merge-with into

Sam Ritchie18:12:57

Presumably you want non-clashing keys to have a vector wrapped around the singleton value in the result yeah?

Isaac Wooden18:12:41

Yeah, is there an easy way to do map-values without dipping into something like spectre?


clojure 1.11 has clojure.core/update-vals

(->> [{:a 1} {:a 2} {:b [3 4]} {:b [5 6]}]
       (map #(update-vals % vector))
       (apply merge-with into))

Sam Ritchie18:12:52

Otherwise if you are stuck on an older version here is one way

Sam Ritchie18:12:28

Into keeps the value as a vector, concat would give you a lazy sequence instead

Isaac Wooden18:12:13

Makes sense, wish there were 1.11 packages available on the clojure/tools homebrew tap

Sam Ritchie19:12:46

Yeah definitely don't pull in sicmutils for that!

😄 1
Sam Ritchie19:12:52

Copy and attribute for sure


TIL map-invert. Anybody know why it’s in clojure.set despite it not appearing to have anything to do with sets? Looks like it’s been there from the beginning.

Sam Ritchie18:12:05

Maybe because the keys form a set so the values will always be sets?

Sam Ritchie18:12:19

After transform… but I do not know the original reason!


clojure.set contains some bits for an in memory relational database


map-invert is used to implement clojure.set/join

💯 1

I like to think that the set of values will be the keys and the cardinality of the map can decrease when doing this