Fork me on GitHub
#beginners
<
2017-10-10
>
akheron05:10:46

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.

akheron05:10:16

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

seancorfield06:10:26

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

seancorfield06:10:28

There's a workflow with clojure.tools.namespace.repl/refresh that addresses your issue but it comes with some baggage...

akheron06:10:55

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

seancorfield06:10:28

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

vinai06:10:11

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

mseddon11:10:08

can anyone review this simple http route matcher? https://pastebin.com/3j0Ua17P

mseddon11:10:14

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

vinai11:10:17

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

mseddon11:10:22

Ah, much better, thanks!

mseddon11:10:03

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

rauh11:10:41

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

mseddon11:10:59

@rauh wow, that's great, thanks!

mseddon11:10:03

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?

tbaldridge11:10:37

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

mseddon12:10:10

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

rauh12:10:03

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

sundarj12:10:54

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

mseddon12:10:00

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

mseddon12:10:40

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?

gklijs15:10:04

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

rinaldi16:10:02

@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

deg17:10:29

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

bwstearns17:10:20

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

noisesmith17:10:47

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

bwstearns17:10:07

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

noisesmith17:10:30

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

bwstearns17:10:40

but yes I missed #{}

noisesmith17:10:29

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

bwstearns17:10:49

ah good call.