Fork me on GitHub
#clojure
<
2016-04-27
>
lwhorton00:04:04

is it possible to do something like:

`(do (def some-var {:some :vals}) (~another-fn ~some-var))
and have ~some-var evaluate to {:some :vals}?

ajmagnifico00:04:28

anyone: can I use [a & {:keys [x y z] :or {x 1 y 2 z 3}] notation in protocol functions and with extend-protocol?

ajmagnifico00:04:54

but when calling the function it won't allow me to leave the :x :y and :z unspecified

ajmagnifico00:04:00

(ArityException)

ajmagnifico00:04:20

it works when I call (f a :x blah :y blah :z blah)

ajmagnifico00:04:51

Looked on clojuredocs and stackoverflow, but didn't find any helpful examples

ghadi01:04:26

varargs not supported on protocols

jimmy05:04:28

hi guys does any one have problem with bouncy castle when running the app as a jar ( test works fine ) java -jar app.jar I got this stacktrace:

Caused by: org.bouncycastle.openssl.PEMException: Unable to create OpenSSL PBDKF: PBKDF-OpenSSL SecretKeyFactory not available  
...
Caused by: java.security.NoSuchAlgorithmException: PBKDF-OpenSSL SecretKeyFactory not available   

danielcompton07:04:51

@nxqd: there are a bunch of results in Google, have you been able to try any?

jimmy08:04:02

@danielcompton: yes I have tried to download the jce unlimited and try out to put vendor configuration on java.security but none of those works.

jimmy08:04:58

<@U051KLSJF>: I've found the solution -_- after sleeping on it for a while, I remember github is the best source to find code solution now. For those who don't know : <https://github.com/middlesphere/jwt-auth-service/blob/210e797802b4bf53bfd03aa639ede54a73154f4d/src/jwt_auth_service/core.clj>

sveri08:04:30

Agreed, I often look for examples on github using its search feature simple_smile

crocket09:04:40

With Clojure, that was intentional, and Cognitect (formerly Relevance) played a major role. The community was built with practicality as a core value. It had the opportunity to learn from the failures of Common Lisp (both as a language and as a community).

crocket09:04:59

What did clojure's community learn from that of common lisp and do better?

crocket09:04:48

To me, it is almost obvious that clojure is better than common lisp as a language, but the community thing is unclear to me.

rohitarondekar09:04:30

Slightly off topic but need recommendations for a good book to learn Java. Something modern/new and not for first time programmers. The only decent recommendation I've gotten so far is Thinking in Java (4ed) which was released quite a long back.

plexus09:04:02

@crocket: could it have something to do with this? http://c2.com/cgi/wiki?SmugLispWeenie

plexus09:04:40

disclaimer: I'm not familiar with the CL community, only with the stereotypes

telent12:04:00

I was there when the SmugLispWeenies page was created (I think ...) and i wouldn't say it was all about CL. There were a lot of smug scheme weenies too (and a lot of friction caused by the conflation of the two communities)

telent12:04:56

the reason I jumped ship from CL (apart from the bit about needing to get paid) was in the end not only that it was painfully awful to do stuff outside of the standard but that so many people seemed to have a vested interest in pretending otherwise

telent12:04:58

but it would also be wrong to regard the "cl community" as homogenous, at least in the (< 2000 year 2008) period I was a part of it

annarcana12:04:19

CL library developers are somewhat notorious for making a thing to MVP for their purposes, and then if they make it available at all, as a lump archive with no continued support or development to be expected.

annarcana12:04:38

Clojure has its flaws, but I find at least that the community is more likely to develop "in the open" on average.

mrg12:04:08

Is core.match still being maintained?

annarcana13:04:25

crocket: Well mostly, and I say this in full acknowledgement of my own guilt, I do find myself frustrated with Clojure documentation culture often. 😉

crocket13:04:46

I thought you were talking about community flaws.

thiagofm13:04:39

@jarcane: I'm also frustrated by how things are generally unfinished or not polished enough. But it's up to us change that.

annarcana13:04:28

crocket: I would consider documentation culture a community issue. Software is made by and for people. simple_smile

crocket13:04:58

I was thinking about abuse toward others.

annarcana13:04:03

(this is why I am also something of a hypocrite here, because I am very, very prone to CL-style "works for me" development)

thiagofm13:04:13

Fork a lib with bad documentation/maintaning and do it better.

annarcana13:04:17

crocket: Ahh, no, I have not encountered much of any of that, thankfully.

annarcana13:04:35

thiagofm: I have in some cases. 😉

crocket13:04:48

#C099W16KZ IRC channels are unfortunately infested by some trolls, by the way. This channel is not.

thiagofm13:04:57

I still work with ruby daily and it's immensurable how bad clojure is when compared to ruby in that side.

thiagofm13:04:36

You can almost find all the possible problems on stackoverflow. Big libraries are well documented. Only frameworks with good documentation survive and so on.

Lambda/Sierra13:04:08

I suspect that's more due to time and number of practitioners.

thiagofm13:04:10

I have a lot of pleasure working with the language, but the ecosystem kind of sucks.

martinklepsch13:04:29

I’m having a weird thing with Aleph’s http client. When making the request with curl it works just fine but when using aleph.http/get the deref just blocks forever. Requests to other than this one resource work, but then again resource works fine with curl.

thiagofm13:04:06

I definitely saw a improvement in the past years in clojure, in that sense though.

sveri13:04:03

@thiagofm: I agree with you to some degree. But, there is a thing that compensates this for me. I think clojure code is most of the times easy to understand. Also the scope of the libraries is kept small mostly. That makes me browse the source code more often than in any other language I have used and I can understand it quiet often and answer the questions myself simple_smile

martinklepsch13:04:14

@sveri: same here but that still is a major hurdle for people just getting started. Also reading a libs code requires some confidence not all beginners have from the start.

telent13:04:33

I'm mildly surprised to see that ruby docs are being held up as an example of how to do it right

c0rrzin13:04:24

I know that doto is intended for interop, but I think that it’s really useful when I want to generate a side-effect and return the previous value, such as:

(doto (compute-val x)
          (gen-side-effect!))
vs.
(let [val (compute-val x)]
  (gen-side-effect! val)
  val)
You guys think this is a code smell?

Lambda/Sierra13:04:38

I think it's fine.

martinklepsch13:04:14

Someone not familiar with doto might be confused what’s being returned, I’d probably decide based on how important it is to optimize beginner-friendliness.

martinklepsch13:04:08

But then again they’d learn about doto this way so I guess it goes either way simple_smile

Lambda/Sierra13:04:22

By the way, re earlier discussion of docs, http://clojure.org accepts contributions — feature guides wanted in particular https://github.com/clojure/clojure-site

plexus13:04:14

Documentation for Clojure itself is already quite good, both with the official site and with free resources like the Brave and True book. The READMEs of many popular libraries are way below par though. (and yes I do intend to submit some PRs to improve that)

plexus13:04:14

there are also counterexamples, there's tons of great stuff in the Luminus docs for example

martinklepsch13:04:22

@plexus: you have some examples in mind right now for popular but under-documented?

plexus13:04:05

Friend and Enlive took me pretty much a day of studying the source each

plexus13:04:02

but yeah, not blaming anyone. Technical writing is really its own skill, and it's not easy to do well

roberto13:04:31

Yes, friend has poor documentation. I found all the auth libs tone very poorly documented

Lambda/Sierra13:04:52

Auth* is a hard problem to generalize.

plexus13:04:21

yeah I looked at buddy as well and was like, "I have not the slightest clue from which angle to approach this thing, I'll just go with Friend"

roberto13:04:24

I struggled with OAuth in friend for days. And I find buddy incomprehensible

plexus13:04:54

although I'm using buddy/hashers now together with friend ¯\_(ツ)_/¯

roberto13:04:02

I'm using friend. Despite its poor docs, it was more approachable than the other so called 'better' auth libs

telent14:04:24

I've used friend a couple of times, I think the single biggest doc change it could make would be a para saying "if this doc does not answer your questions, feel free to look at the source code - it does not bite"

telent14:04:48

but the number of ruby libs I've used where the documentation is a README and then a set of entirely unhelpful rdoc files and then you click on 'view method source' and the method is a one-liner that calls some other internal method and then you click 'view on github' and get a 404 because it's moved

telent14:04:27

and that's before you even start worrying about whether the version of the library you're running is the same one as the documentation (which you found by googling) is written for

telent14:04:11

I'm told that python does it a lot better. I tend to believe that no matter what ecosystem you're in it looks from the outside like everybody else does it better

telent14:04:21

see also http://words.steveklabnik.com/rails-has-two-default-stacks description of 'documentation which describes only the differences'

juliobarros14:04:41

I have a "Cyclic load dependency" problem. I have a db namespace that needs to put things on a job queue and a job queue ns that needs to do the work and write back to the database. Can’t figure out how to break the cycle. Any ideas?

dpsutton14:04:11

it sounds like your db namespace is doing other things than writing to the db. for intsance, it enqueues things

fasiha14:04:47

@juliobarros: I have a similar issue (one ns reads data from hardware, another ns serves it over the web). I would put functions that interact with the db in the db namespace (taking and putting), and the queue ns just calls the relevant functions in db? Would that work?

dpsutton14:04:53

make things just directly talk to the queue ns and let that delegate how it gets to the db ns?

Lambda/Sierra14:04:37

Split the work: db API functions in the db ns, queue API functions in the queue ns, work that involves both in its own ns.

juliobarros14:04:51

@dpsutton … yeah 😄 but I need to write to the DB and enqueue when something changes. Didn’t want to make every other NS that needs to save also “know” that it needs to enqueue.

dpsutton14:04:41

do what stuart said. Make a single ns that people call. inside of there its smart enough to know when just put in db, db and queue, or just queue

dpsutton14:04:50

then your caller's only need a single interaction ns

borkdude14:04:55

"work that involves both" often goes by the name 'controller', I find it helpful to think of the structure of e.g. Rails or Play apps when doing Clojure

borkdude14:04:20

I've had exactly this problem in some web application where I tried to do too much in one namespace that represented some domain (and had a dependency on some other domain which in turn needed a dependency in the other direction)

juliobarros14:04:07

Thanks all. Let me think this through. I hear what you are saying but am not sure how to best apply it to what I want to do.

risto15:04:35

@rohitarondekar check out Big Java

rohitarondekar15:04:46

@risto: Thanks. Which one did you mean? There is a early objects and late objects version. The book website doesn't seem to have any info on the target audience

risto16:04:32

though it seems like early and late objects is his latest editions, late objects being the next logical step to read

risto16:04:52

The book i referenced is for beginners. It doesn't cover all of the advanced topics

rohitarondekar16:04:04

@risto: ok thanks I'll take look simple_smile

audaxion19:04:52

For example, when a piece matches a

:waypoint
the next piece need to be added as a new key
:airway
for all waypoints until the next match

slipset19:04:37

I’ll try to ask again...

slipset19:04:38

I’m working with zippers and xml, and for some reason code like this returns the empty list:

slipset19:04:45

(def xml "<foo id = \"qix\">bar</foo>")
(def z (-> xml parse-str xml-zip))
(xml-> z
       :foo)

slipset19:04:38

This seems strange to me as

slipset19:04:42

(xml-> z
       (attr= :id "qix")
       text)

slipset19:04:43

works, as in it returns (bar) as expected

slipset19:04:38

ah, it seems to be an issue on this already:

Alex Miller (Clojure team)20:04:13

I actually looked at this for a bit a couple months ago

Alex Miller (Clojure team)20:04:27

but ran out of timebox before I understood why

slipset21:04:40

it only fails if you try to match on the first element.

slipset21:04:52

commented on the issue

Doug Kirk21:04:38

I keep needing to apply a fn to a val if the fn is defined, otherwise return the val. Is there an idiomatic way to do that? Something like

(defn apply-if [f value]
  (if f
    (f value)
    value))

slipset21:04:35

also, I was using clojure.data.xml/parse-str instead of clojure.xml/parse

hiredman21:04:53

kirked: are you sure you don't want fnil?

hiredman21:04:00

apply-if is not exactly fnil but I suspect whatever you are doing with it, if you think about it slightly differently, you can use fnil instead

Doug Kirk21:04:40

I think in my case the default value would always be identity

Doug Kirk21:04:36

I could use fnil, but I was thinking perhaps there's a standard function somewhere whose name I don't know that essentially does the above.

hiredman21:04:51

for example, if you where counting things (reduce (fn [counts thing] (update-in counts [thing] (fnil inc 0))) {} seq-of-things)

Doug Kirk21:04:26

My use case is doing configuration-driven transforms on Google Analytics query results for a graphing library. So in some cases the transform will be defined, in other cases it won't be (based upon the form needed to supply the graphing library).

hiredman21:04:14

((fnil apply identity) (get config :fn) [arg])

Doug Kirk21:04:50

I can see how that works. But if I have to write my own code to apply a function if it's defined, I think the if-based one reads easier. I was hoping for something in core that I couldn't find.

hiredman21:04:16

I would recommend making apply-if take multiple arguments instead of just one, like apply does, although figuring out what the return value should be in the else then would be kind of tricky

hiredman21:04:59

(defn apply-if [f & values] (if f (apply f values) (first values))) or something

hiredman21:04:46

so your apply-if is more closely matched with apply

hiredman21:04:01

the else case is kind of blah though

hiredman21:04:31

obviously you should do it with spectre, and define a spectre navigator that only visits things you have defined transforms for 😛

noisesmith22:04:08

kirked: I don't understand what you mean by " if I have to write my own code to apply a function if it's defined" - apply is part of clojure, and the fnil apply thing works as is

noisesmith22:04:23

user=> ((fnil apply list) (get {:f + :g -} :f) [1 2 3])
6
user=> ((fnil apply list) (get {:f + :g -} :h) [1 2 3])
(1 2 3)

hiredman22:04:20

well, you do have to write (fnil apply identity) everywhere you would want to use it, so you meant want to (def apply-if (fnil apply identity)) but once you do that, you might as well optimize for understanability over brevity, which, well, I think most people would comprehend the if version faster

Doug Kirk22:04:21

@noisesmith: I meant "if there's not a function in core that already does this"

noisesmith22:04:26

nb. to me fnil is a standard tool like comp or map that doesn't need to be hidden by an abstraction

noisesmith22:04:14

it has simple semantics, and is useful precisely because it is weaker and easier to understand than if

noisesmith22:04:40

(just as reduce is useful because it is weaker than loop)

c0rrzin22:04:10

if you’re using get to extract the transform fn, you can always (get config :fn identity)

noisesmith22:04:10

good point, and identity is a bad fallback because there might be more than one arg in the collection (which is why I used list instead)

richiardiandrea22:04:30

hello folks, a question: is timbre going to replace println out of the box?

richiardiandrea22:04:37

ok maybe i forgot some conf...