Fork me on GitHub

I'm new to Clojure and CIDER. I use C-c C-k while developing to load a file to the REPL. But if I remove a function from the file, it still stays in the namespace that's in the REPL, right? If the namespace happens to be a test namespace, then a removed/renamed test will also be run with C-c C-t n.


So, is there a way to load a file to the REPL in a way that the namespace it contains would be completely replaced?


The simple answer is "yes" but the practical answer is "it's hard" @petri


There's a workflow with that addresses your issue but it comes with some baggage...


@seancorfield Ok, so there's something more to consider than just hitting C-c C-x?


Yeah, it relies on your whole application and your workflow following the "reloaded" process.


@petri As a quick fix, running (ns-unmap 'your.ns 'removed-test) will get rid obsolete tests, too. You can use *ns* if you are in the test namespace in the repl. Also, commenting out (testing... forms with #_ for example instead of full tests helps sometimes.


can anyone review this simple http route matcher?


also I apologise for pastebin, apparently it really sucks at highlighting clojure. perhaps there's a better site


@mseddon You can add code snippets to this slack directly using hte [+] symbol on the left.


Ah, much better, thanks!


I'm not thrilled by my (apply hash-map (mapcat ... at the bottom, it feels like there's probably a better way


@mseddon 1. Why clojure.string not aliased? 2. Don't use str as a binding name. 3. Why not destructure on the last line? 4. Use when-some on second last line. 5. Ln#13: Doens't join take an interpose parameter? 6. Ln#5: (zipmap (range 1) ... 7. But overall, all minor suggestions here. Looks pretty good.


@rauh wow, that's great, thanks!


Only one I couldn't get to work was (range 1), since that returns [0..1], rather than [1..], is there a different function for that?


@mseddon also for future reference, (into {} [[:a 1] [:b 2]]) -> {:a 1 :b 2}


@tbaldridge doh! i knew there was a way to do that sanely, thanks


@mseddon Yeah, it looks like range was bad advice. I always have to look up the params 🙂


@mseddon i think (for [[idx key] imap] [key (matches idx)]) is a tad clearer than that map


@rauh 🙂 @sundarj oh, yes, I see what you mean. Let's try that


thanks guys, that's really been immensely useful

Jim Rootham13:10:49

I would like to have separate names for test and production uberjars compiled from the same project.clj file. Is that possible? Can you put an uberjar-name key is a profile and make uberjars with 2 different profiles?


@jrootham that's possible, you can set the uberjar-name in a profile, so when you make an uberjar with that profile, it gets that name.


@jrootham You can use the profiles feature for that:

❯ lein help with-profile
Apply the given task with the profile(s) specified.

Comma-separated profiles may be given to merge profiles and perform the task.
Colon-separated profiles may be given for sequential profile task application.

A profile list may either be a list of profiles to use, or may specify the
profiles to add or remove from the active profile list using + or - prefixes.

For example:

     lein with-profile user,dev test
     lein with-profile -dev test
     lein with-profile +1.4:+1.4,-dev:base,user test

To list all profiles or show a single one, see the show-profiles task.
For a detailed description of profiles, see `lein help profiles`.

Arguments: ([profiles task-name & args])
Then you could have:
❯ lein with-profile dev my-thing uberjar # dev
❯ lein with-profile prod my-thing uberjar # prod


Is there a better way to say (defn negligible? [x] (if (seqable? x) (empty? x) (not x)))?


does this work? (defn negligible? [x] (contains? #{[] {} nil false} x))


there’s also () “” #{} and a few others the original encompases


() is covered here. (= '() []) returns true


oh right, I forgot contains? uses collection equality d’oh


but yes I missed #{}


and "" and (into-array Object []) etc. - lots of things are sequable but not equal to clojure colls


ah good call.