Fork me on GitHub

best way to delete dependency from local repo and force redownload?

Chris O’Donnell02:07:54

@josh_tackett: you can delete it from the maven cache in ~/.m2


@codonnell: Ya I think that’s the plan. Was hoping leinigen had an easier way

Chris O’Donnell02:07:36

not that I know of


@codonnell: the dependency is a java dep, would it still be in /.m2? I don’t see it in there

Chris O’Donnell02:07:52

@josh_tackett: That's odd. Did you run lein deps?


it already downloaded, but I need to erase and redownload

Chris O’Donnell02:07:16

I added [commons-codec/commons-codec "1.4"] to a project.clj and I see ~/.m2/repository/commons-codec/commons-codec/1.4


haha ya I can’t find it in .m2


I see all my other libs


I don’t know wha the name should be




that’s the jar

Chris O’Donnell02:07:32

what did you write to add it in your project.clj?


A very small tidbit to keep core library merge from replacing data in earlier maps with nils in later maps. If there are more sensible/idiomatic ways to do this, I'd love feedback, and if not, I offer it as a tiny utility function. 🙂


(though I suppose the [nil _] isn't necessary)


Is there a library to read various mailbox formats?


Hey all - implemented this in 1.9.0-alpha10 with the inst-ms --> Any advice on how to implement in 1.8.0 ??

(defn older-than-mins?
  "accepts a date time format and a mins arguement which represents minutes and returns a boolean if the datetime is greater than the mins old"
  [^Date d mins]
  (let [now-ms (inst-ms (Date.))
        min-ago-ms (- now-ms (* mins 60 1000))]
    (< (inst-ms d) min-ago-ms)))


Suppose I will rebuild this..

(defprotocol Inst
  (inst-ms* [inst]))
(extend-protocol Inst
  (inst-ms* [inst] (.getTime ^java.util.Date inst)))
;; conditionally extend to Instant on Java 8+
  (Class/forName "java.time.Instant")
  (load "core_instant18")
  (catch ClassNotFoundException cnfe))
(defn inst-ms
  "Return the number of milliseconds since January 1, 1970, 00:00:00 GMT"
  {:added "1.9"}
  (inst-ms* inst))
(defn inst?
  "Return true if x satisfies Inst"
  {:added "1.9"}
  (satisfies? Inst x))


@seancorfield: I've just read about and had a little peek at Engine. It's really cool! Significantly better approach to approaching purity in clojure projects.


I’m trying to coerce org.joda.time.DateTime (with clj-time) instances to and from an SQLite database without much luck.


Putting the DateTime into a TIMESTAMP column in the database produces a long, reading it back just produces a long.


I am requiring clj-time.jdbc, so the protocol/type extensions should have been made.


@seancorfield: thanks for the links! tldr: partial for functions that play well with partial, #() for all the others. I think that's inconsistent, and #() is ugly, both visually and because #() being a reader macro you can't map or apply it as a function like you can with partial


There’s always (fn) which is what #() is sugar for.


yeh but still, you can't use it like partial, e.g. (map partial my-fns my-default-args)


and more verbose


(esp if you're using Clojure pretty symbol)


@octo221: idioms aren't unbreakable rules... they just guide you towards a design which others will expect... and can indicate when perhaps you're doing something unusual; that might be suboptimal... I wouldn't say your case of (map partial fns my-args) is unusual (it might be over engineering or it make be totally the best thing to do) but its not especially common... If your functions need to be partially appled in a different order - I would question the argument orders of those functions... if you think they're still correct, then there's nothing wrong with defining a reverse-partial. Just be aware that people might find it unfamiliar


I personally think between -> ->> partial #() and fn you have enough coverage in the standard library for most things


that's not to say other combinators etc aren't useful though


@rickmoynihan: yeh that example was contrived, but I have actually used it once! my most common use-case for partial-right is with get, to default the path or default arg e.g. (rp get path) or (rp get default) (rp means right-partial), that is a very common use-case


and using partial mean I can comp it with other fns


as I could with fn but it's less consistent


I don't tend to mind using the odd #(get %1 %2 :default) its not that common to need to partially apply at the end - assuming the library authors have thought about order


(i mean, it's the same in the end)


eh I guess I just find those % noisey


but they make it obvious whats happening


partial is obvious


yeah but say the alphabet backwards, reversing things in your head isn't easy 🙂 I understand putting something in the last position is 90% of your usecase though.


hmmmm, is it considered an anti-pattern to implement actual functionality in Components? as in, instead of just the start and stop functions, also implement, say, a do-stuff-with-component function ?


yes, partialling the last position is 90% of my usecase definitely


another example is pow, (rp pow 2) for squaring


and / (rp / n)


could do (partial * (/ 1 n)) but it's uglier


@lmergen: In my opinion, yes it is a little OOP. It also makes your code somewhat more modular, as you can drop in a mock email implementation. I think it's okay to look to OOP for side effects and stateful things, because that's what OOP is good at. But the actual business logic (generating log messages, doing math) should be done before calling your sender with it. Does this make sense?


right, i think i'm even a bit more careful with this, since it's a slippery slope, and suddenly half your module's functions are defined as a part of your Component, rather than passing the component state around


ah! but it's actually defined as part of a protocol, If you wanted to leave component, or perhaps do some tests, anything which implements that protocol will work in it's place as an argument.


Counter that with having something like

(defn foo
  (some.library.that.does.smtp/send! smtpconn {:msg "foo"}))
If you wanted to test it you couldn't! But with:
(defn foo
  (protocols/send! EmailerImpl {:msg "foo"}))
Anything can be dropped in, as long as you extend that protocol.


yes, which feels a lot like OOP interfaces / inheritance to me


aren't callbacks the more FP way of doing this ?


But I think that's okay for stateful things like this. It's a useful pattern. I've never seen callbacks used for this purpose. I think it is somewhat similar though.


Although, there is an argument for doing it via core.async. But that brings it's own trade-offs.


With a callback you say "call this function to do the actual sending" with a protocol you say "I'll give you something you can call the actual function on to do the sending" However, when it becomes more complex than email, or you want to ignore the functions it calls ("it does something with the database, I don't care what")


well, i think that one of the more powerful things about FP is that it makes state more explicit, and this makes state implicit, which means you should be careful


but yeah, there are various philosophies for this, i think yours is one of the more pragmatic ones


but i'd be very, very careful about wrapping state like this


Absolutely! Ideally, this kind of work would only happen in a few fringe places of your application. I like to think of it as being "layered." One of those layers is the "system" or "state" layer, which is in charge of calling your pure logic layer, and writing it to the database.


it's perfectly fine imho, it's kinda equivalent of using a closure


@weavejester: sorry to bother (@otfrom voluntold me to ask you 🙂 ), but I wondered how to get runtime errors piped to the logs when using compojure (sweet). I tried to do that with a basic middleware, but it doesn't work - I suspect the exception is getting caught to produce a 500 somewhere else see


is there a way to get the actual exception to the logging stack?


@weavejester: actually, never mind, it's not a compojure thing, I found the solution facepalm


Does anyone have an example of using hickory select-next-loc I am trying to do a replace on a clojure zipper but I either get infinite loops or nullpointer exceptions. Clearly missing something


When is clojure conj this year?

Alex Miller (Clojure team)16:07:54

not announced yet, but will be first weekend of Dec


I love a good sentence that nullifies itself


@dominicm: Thanks. Engine was very much a scratch-an-itch concept a year ago, but it’s an interesting idiom to program against for production code when your business logic has historically been peppered with both database queries and updates 😆


Yeah! I'm looking at one of those right now.


@octo221: As others have said, if you find yourself reaching for #() often, you should question the argument order of the functions you’re calling and see whether those functions are idiomatic or not — and yes you can map and apply those anonymous functions just fine: (apply #(+ %1 %2) [1 2]) => 3


@octo221: Also, if you find yourself needing a particular argument order often for a given function, you could always write a HOF wrapper...


Hi guys! I am using clj-http.client and I want to retry if Internal Server Error. How can I do that?o


I am using clj-http.conn-mgr too.


Catch the exception and try again?


there are also non-exception based alternatives:


Someone also just recently posted this library on the google group:


That may be more machinery than you need, though


hi, there. I am trying to convert the paginated JSON result returned by an HTTP query to a REST interface into something sequential. A lazy-seq could work but, is there any idiomatic way to return this JSON result as elements in a channel? Thanks in advance!


I don’t understand when/why to use “do” in clojure


anybody have a clear answer?


Use do when you want to evaluate a series of expressions but only care about acting on the value of the last expression


@candiedcode: wrap expressions in do if you need to accomplish multiple tasks when only a single expression is allowed


(if test


I don’t use it often in that manner, but it’s useful when needed


i just tested in the repl and confirmed


For those using schema in compojure-api, how do you like to organize schema for a project? Store in one big file from which they can be drawn? Or broken into separate files based on resource?


candiedcode: it's often used when side effects are involved, maybe you need to append a string to a file and then return that string


so you'd have:

  (spit "abc.txt" "foo)


@candiedcode: this is often used for side effects


the time I most often use it is an 'if' when I need to take more than one action


that’s almost the exact example we did in the repl

Alex Miller (Clojure team)21:07:41

I’d go so far as to say it’s only useful for side effects, because you are ignoring the return value of all but the last expression


and in macros, (do ~@body)

Alex Miller (Clojure team)21:07:21

again though - having multiple body expressions will have no effect unless they have side effects

Alex Miller (Clojure team)21:07:05

not saying you’re wrong, just that it stems from the same reason