Fork me on GitHub
#clojure
<
2017-09-20
>
bigdaddys1oth02:09:02

Hey all, I've been learning Clojure for like 3 months now and I really enjoy it. I think my main block with becoming a savant is finding small practical programs to write to learn Clojure in more depth. I've been going through Clojure For the Brave and True, and it's definitely helped with learning Clojure, but I want a bit more.

yogidevbear07:09:26

@bigdaddys1oth I'd also highly recommend Living Clojure (by @U04VAD6RL) and Programming Clojure 3rd ed. (by @U064X3EF3 et. al.) https://pragprog.com/book/shcloj3/programming-clojure-third-edition

jumar08:09:56

@bigdaddys1oth Besides the book suggestions (all of them great although Joy of Clojure can be a bit tough to follow) I recommend http://exercism.io, 4clojure, Parens of the Dead (http://www.parens-of-the-dead.com/), Tim Baldridge's Clojure Tutorials (https://www.youtube.com/channel/UC6yONKYeoE2P3bsahDtsimg), https://lambdaisland.com/, and https://purelyfunctional.tv/ Some of them are paid, but I think they are well worth the cost.

jumar09:09:22

Also check "beginning to learn Clojure after imperative programming my whole life": https://groups.google.com/forum/#!topic/clojure/FVhL4ZZxHy8

manutter5111:09:33

If you’re looking for programming challenges, you should check out Project Euler https://projecteuler.net/. Tends to be more math-oriented and not specific to clojure, but they’ve got some great problems to work on.

rovanion09:09:07

I really can't get compojures destructuring working right. Can anyone tell me if I can make this route look nicer? (POST "/api/request-priority" req #(api/request-priority (:body req)))

delaguardo09:09:38

How about (POST "/api/request-priority" {body :body} (api/request-priority body))

rovanion10:09:01

Yeah, thank you. That seems to be working.

rovanion10:09:31

(POST "/api/request-priority" {:keys [:body]} (api/request-priority body)) also seems to do the trick.

rovanion10:09:05

But if anything this cements how hard it is to reason about someone elses macros at times and how one should try to avoid them.

delaguardo10:09:53

compojure destructuring is the same as in clojure, you just need to keep in mind that incoming request will be in ring map format, as described here - https://github.com/ring-clojure/ring/wiki/Concepts#requests In any route definition you can get access to any upper level key with constructions like - {:keys [body server-port uri ... etc]} or, if you need to get some nested key with {{some-key-in-body :some-key-in-body} :body} I’m using this gist for remembering how destructuring works in clojure - https://gist.github.com/john2x/e1dca953548bfdfb9844 Maybe this will helps you as well)

noisesmith16:09:42

fyi {:keys [:body]} may sometimes work by accident but the correct version is {:keys [body]} (see also :strs and :syms, I bet you can guess what they do)

mkvlr13:09:32

does anybody know of a bcrypt library with support for 2b other than this branch https://github.com/anebril/jBCrypt/commits/gcsvn-merged-0.4-overflow-fix ?

ghadi15:09:00

Have you checked whether bouncy castle supports it?

ghadi15:09:01

It says it corresponds to the OpenBSD implementation, not the original 1999 paper

ghadi15:09:39

I think that must be 2b

mkvlr08:09:03

Just saw this now, will check it out, thanks a lot!

mkvlr13:09:52

would like to avoid having to package this

avi14:09:08

just wondering, is there a more concise/elegant way to map a Java method (e.g. name()) on a coll/seq of Java objects than (map #(.name %) coll) ?

schmee14:09:27

I think that is the correct way to do it, there is http://clojuredocs.org/clojure.core/memfn but I haven’t seen that used much

kendall.buchanan14:09:07

Anyone familiar with a way (ideally in vim) to trace every use of a var or function? vim-fireplace will trace an invocation of a function back to its definition, but I’m looking for the reverse. Thoughts?

cpmcdaniel15:09:02

Does anyone have a handle on how we are doing on Java 9 support (generally)?

dominicm15:09:24

Clojure 1.9 is all sorted for it afaik

dominicm15:09:41

the beta1 changelog suggested as much

dominicm15:09:53

and even that was just a minor change.

Alex Miller (Clojure team)15:09:16

since then, CLJ-2077 was applied and is included in 1.9.0-beta1

dominicm15:09:39

A minor clarification to what that google groups says: Boot does not use the bootclassloader, so works today with Java 9 (I suspect, I haven't tried myself).

ghadi15:09:47

Just to split hairs, Clojure has always worked on Java 9, it's lein and boot that didn't.

dominicm15:09:24

ah, Boot didn't work with Java 9 because of https://github.com/tobias/clojure-java-9/issues/3

ghadi15:09:21

boot does now (2.7.2)

Alex Miller (Clojure team)15:09:26

there are apparently issues with the clojure-maven plugin as well although I haven’t seen a report on that yet

genec16:09:47

is Leiningen ok with Java 9?

dominicm16:09:40

@kendall.buchanan Hi. I have a trick that works if you have refactor-nrepl, but it's basically a large ugly blob.

dominicm16:09:58

It used unite.vim, I haven't really maintained it, so it's gone now I think

dominicm16:09:27

a lot of it is unite-specific formatting. I had a version that loaded into the quickfix buffer.

dominicm16:09:22

(btw, you should join us in #vim-fireplace)

mbertheau16:09:45

How would you put (mapv #(identity {:subject % :count (:count %)}) employees)) more concisely?

ghadi16:09:24

IMHO it's not easily readable -- defn the mapping function top-level to improve it

ghadi16:09:48

if you def it to ! then it'll be really concise 😆

dominicm16:09:09

(mapv #(hash-map :subject % :count (:count %)) employees) is one start I guess

noisesmith16:09:14

#(hash-map :subject % :count (:count %)) is nicer I think

mbertheau16:09:05

No way to leverage the literal map notation here?

dominicm16:09:17

I have a utility I came up with I call "juxtamap", which combines juxt & hash-map which would be perfect for this: (mapv (juxtamap {:subject identity :count :count}) employees) Of course, introducing new syntax is not always a good thing.

dominicm16:09:33

@mbertheau not without switching to (fn [%] {…})

mbertheau16:09:28

Thanks for your input! I'll go with the hash-map way

mbertheau16:09:48

@dominicm: juxtamap looks nice!

dominicm16:09:34

(defn juxt-map [& {:as x}]
  (comp #(zipmap (keys x) %) (apply juxt (vals x))))

(map (juxt-map :a inc :b dec) [1 2 3])
^^ quickly came up with this new version which resembles hash-map a little more.

kendall.buchanan16:09:53

@dominicm Hey, I appreciate your suggestion—I’ll check it out.

misha18:09:56

@mbertheau (mapv #(-> {:subject % :count (:count %)}) employees)) opieop

noisesmith18:09:07

@misha do has the same result and is less obfuscated

noisesmith18:09:16

(just using fn, or a function meant to make a hash-map, is still better than either option)

misha18:09:15

-> uses less pixels than do does troll

staypufd19:09:14

Hello all I’m having a issue with getting nrepl to run in a Docker container using DockerMac. I’ve exposed port 7000 and from my -main function the nreql/start function is called. The app is started via a CMD in the Docker file --> CMD [“lein”, “uberjar” “-Djava.net.preferIPv4Stack=true”] (The prefere IP4 was what I found online as a suggestion that would fix this but it didn’t work) The error I get is: ‘Caused by: java.net.SocketException: Protocol family unavailable at java.net.PlainSocketImpl.socketBind(Native Method)’ error. So I wondered if anyone else has worked around that problem

staypufd19:09:22

Any help is appreciated

gonewest81819:09:43

lein uberjar builds and packages the jar but it doesn’t run the jar.

gonewest81819:09:59

Since you already have the sources in the container you could CMD ["lein", "run", "--", ...] with whatever parameters you need and don’t bother package the jar.

mike_ananev19:09:15

tomorrow release of java 9. is lein ready for java 9?

ghadi20:09:29

there's some scrollback about this in #clojure this morning

staypufd20:09:53

@gonewest818 I actually have CMD that runs it later, but I guess I could run it with lein

gonewest81820:09:01

Or, you could build the uberjar outside the container and ADD it in. Then your Dockerfile would contain something like

ADD target/uberjar/myapp-1.2.3-standalone.jar /
CMD ["/usr/bin/java", "-jar", "/myapp-1.2.3-standalone.jar"]

gonewest81820:09:07

sorry … crossed messages with you. Yes, we said the same thing.

staypufd20:09:37

the weird thing is that I get that error about java.netSocketException just by having the jar run with java

gonewest81820:09:13

I think you said at the beginning you were having problems with nrepl… Is this right — you’re using ring (with jetty?) to expose a web server on port 3000, and also something like (clojure.tools.nrepl.server/start-server :port 7000) to expose a repl on port 7000?

gonewest81820:09:32

Oh, wait. Our dockerfiles are not the same thing. When you do CMD ["lein", "uberjar"] that’s happening in the docker container. But you haven’t added the sources yet, so there is nothing to build there. That command is probably failing with “Couldn’t find project.clj, which is needed for uberjar”

gonewest81820:09:14

The next line ADD target/uberjar/backend-clojure.jar /backend-clojure/app.jar will try to add the most recent uberjar you built in the project directory on your mac.

gonewest81820:09:27

Which might be there, or might not, or might not be current.

gonewest81820:09:03

Never mind what the app does, it’s just a little toy example, but I wrote a little utility script docker_build.sh that ensures a fresh uberjar is packaged and then it invokes docker build -t .. to build an image that runs the container.

staypufd20:09:03

@gonewest818 I have my local dir mapped to the container, so it finds the sources and uberjars them. The web app itself runs fine. Just haven’t been able to get the nrepl to run. As I get that SocketException: Protocol family unavailable

staypufd20:09:38

looking at your benchcurl example though, so thanks

gonewest81820:09:06

Ok. As far as I know you can docker run -v but you cannot docker build -v so your CMD ["lein", "uberjar"] must be erroring. It must be only because you’re then doing ADD that there is a jar to be run. So anyway, we can go back to focus on the socket error.

chrisdavies20:09:54

Does anyone here use VS Code with Clojure? Just curious, as my team is evaluating Clojure, but currently uses VS Code for all other languages (Ruby, SCSS, CSS, HTML, JavaScript, etc). Visual Clojure is working well for me, but one thing I'm noticing is that when I tab/shfit + tab, it messes up my map indentations:

chrisdavies20:09:10

{:value name
:name "name"
:on-change sync-field
:placeholder "Name"}

gonewest81820:09:56

by the way @staypufd we should move this discussion to the #docker channel

chrisdavies20:09:14

^^^ That appears to be VS Code, not Visual Clojure. Wondering if anyone has found a good workaround for that?

bbloom23:09:59

i was curious how Rust deals with things like clojure.core/update and i’m not sure if i should be impressed or horrified by this: https://doc.rust-lang.org/std/collections/hash_map/enum.Entry.html

bbloom23:09:44

it’s definitely a clever solution