This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-19
Channels
- # admin-announcements (2)
- # aws-lambda (3)
- # beginners (66)
- # boot (61)
- # cider (1)
- # cljs-dev (17)
- # clojure (100)
- # clojure-austin (4)
- # clojure-brasil (1)
- # clojure-canada (8)
- # clojure-quebec (6)
- # clojure-russia (48)
- # clojure-sg (6)
- # clojure-spec (37)
- # clojure-uk (61)
- # clojure-ukraine (2)
- # clojurescript (80)
- # core-async (13)
- # cursive (20)
- # datascript (37)
- # datomic (2)
- # defnpodcast (4)
- # emacs (5)
- # funcool (3)
- # hoplon (11)
- # jobs (7)
- # juxt (26)
- # lein-figwheel (48)
- # leiningen (3)
- # luminus (3)
- # om (34)
- # om-next (5)
- # onyx (5)
- # protorepl (6)
- # re-frame (10)
- # reagent (9)
- # rethinkdb (16)
- # ring-swagger (5)
- # spacemacs (14)
- # specter (54)
- # untangled (36)
- # vim (75)
- # yada (1)
best way to delete dependency from local repo and force redownload?
@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
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
@josh_tackett: That's odd. Did you run lein deps
?
it already downloaded, but I need to erase and redownload
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
SSAM-ARES-DEV-SNAPSHOT.jar
that’s the jar
what did you write to add it in your project.clj?
found it 🙂
great 🙂
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
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
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))
@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
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 ?
it feels a bit too OOP to me, but I just saw juxt using it here: https://github.com/juxt/modular/blob/master/modules/email/src/modular/email/log_emailer.clj#L10
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, 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.
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.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
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.
@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
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
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?
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 😆
@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
there are also non-exception based alternatives: https://github.com/dakrone/clj-http#exceptions
Someone also just recently posted this library on the google group: https://github.com/sunng87/diehard
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!
@lucelios: I used this http://stackoverflow.com/questions/1879885/clojure-how-to-to-recur-upon-exception
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
(do
…
…)
...)
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
@candiedcode: this is often used for side effects
that’s almost the exact example we did in the repl
thanks @bhauman !
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
again though - having multiple body expressions will have no effect unless they have side effects
not saying you’re wrong, just that it stems from the same reason