Fork me on GitHub
#clojure
<
2016-07-19
>
josh_tackett01:07:41

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

josh_tackett02:07:25

@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

josh_tackett02:07:49

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

josh_tackett02:07:22

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

josh_tackett02:07:59

haha ya I can’t find it in .m2

josh_tackett02:07:07

I see all my other libs

josh_tackett02:07:17

I don’t know wha the name should be

josh_tackett02:07:19

SSAM-ARES-DEV-SNAPSHOT.jar

josh_tackett02:07:23

that’s the jar

Chris O’Donnell02:07:32

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

gowder04:07:52

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. 🙂 https://gist.github.com/paultopia/78ba6791d7eba48293da45d9d5d58c57

gowder04:07:48

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

seylerius04:07:49

Is there a library to read various mailbox formats?

esinicin04:07:43

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

esinicin04:07:46

Suppose I will rebuild this..

(defprotocol Inst
  (inst-ms* [inst]))
 
(extend-protocol Inst
  java.util.Date
  (inst-ms* [inst] (.getTime ^java.util.Date inst)))
 
;; conditionally extend to Instant on Java 8+
(try
  (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]
  (inst-ms* inst))
 
(defn inst?
  "Return true if x satisfies Inst"
  {:added "1.9"}
  [x]
  (satisfies? Inst x))

dominicm07:07:39

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

jonathanj07:07:24

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

jonathanj07:07:58

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

jonathanj07:07:14

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

octahedrion08:07:04

@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

jonathanj08:07:36

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

octahedrion08:07:49

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

octahedrion08:07:21

and more verbose

octahedrion08:07:39

(esp if you're using Clojure pretty symbol)

rickmoynihan09:07:09

@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

rickmoynihan09:07:05

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

rickmoynihan09:07:00

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

octahedrion09:07:30

@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

octahedrion09:07:37

and using partial mean I can comp it with other fns

octahedrion09:07:29

as I could with fn but it's less consistent

rickmoynihan09:07:44

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

octahedrion09:07:48

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

octahedrion09:07:12

eh I guess I just find those % noisey

rickmoynihan09:07:41

but they make it obvious whats happening

octahedrion09:07:52

partial is obvious

rickmoynihan09:07:36

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.

lmergen09:07:51

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 ?

octahedrion09:07:14

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

octahedrion09:07:08

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

octahedrion09:07:25

and / (rp / n)

octahedrion09:07:48

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

dominicm10:07:14

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

lmergen10:07:38

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

dominicm10:07:23

ah! but it's actually defined as part of a protocol, modular.email.protocols/Emailer. 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.

dominicm10:07:39

Counter that with having something like

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

lmergen11:07:16

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

lmergen11:07:40

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

dominicm11:07:10

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.

dominicm11:07:01

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

dominicm11:07:51

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

lmergen11:07:13

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

lmergen11:07:07

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

lmergen11:07:25

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

dominicm12:07:03

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.

mpenet12:07:43

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

elise_huard12:07:21

@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 https://github.com/MastodonC/witan.app/pull/189/files#diff-4200ec36c41edb17412c781a9610a6f5R236

elise_huard12:07:03

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

elise_huard12:07:01

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

flyboarder14:07:54

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

josh_tackett15:07:30

When is clojure conj this year?

Alex Miller (Clojure team)16:07:54

not announced yet, but will be first weekend of Dec

mj_langford16:07:07

I love a good sentence that nullifies itself

seancorfield17:07:37

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

dominicm17:07:10

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

seancorfield17:07:56

@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

seancorfield17:07:14

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

cupello18:07:15

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

cupello18:07:22

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

dg18:07:03

Catch the exception and try again?

semperos18:07:30

there are also non-exception based alternatives: https://github.com/dakrone/clj-http#exceptions

dg18:07:41

Someone also just recently posted this library on the google group: https://github.com/sunng87/diehard

dg19:07:51

That may be more machinery than you need, though

cristobal.garcia19:07:31

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!

candiedcode20:07:13

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

candiedcode20:07:29

anybody have a clear answer?

donaldball20:07:25

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

bostonaholic20:07:57

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

bostonaholic20:07:37

(if test
  (do
    …
    …)
  ...)

bostonaholic20:07:03

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

candiedcode20:07:10

i just tested in the repl and confirmed

tom21:07:50

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?

scriptor21:07:59

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

scriptor21:07:22

so you'd have:

(do
  (spit "abc.txt" "foo)
  "foo")

bhauman21:07:56

@candiedcode: this is often used for side effects

bhauman21:07:41

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

candiedcode21:07:50

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

dg21:07:12

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