Fork me on GitHub
#clojure
<
2015-12-02
>
Ivan Fedorov09:12:53

Is there anybody who can consult on queues and executors? I'm building email service in my monolith app, and the app has few producers of standardized email task. Producers store these tasks to a single queue. And I want to add a consumer to this queue, but I don't know how to initialize it properly. I imagine it should be some managed thread, controlled by a thread pool, or executor or something. So, what is a proper way to initialize the consumer? I would read some sources and examples if you know some. Thanks.

dm309:12:41

@ognivo, you can use core.async to make that simple

dm309:12:03

then the threads and queues will be hidden from you

Ivan Fedorov09:12:30

@dm3 hm, I'll check that, thanks.

thheller12:12:02

@ognivo you usually just create an executor via the Executors class (eg. (Executors/newFixedThreadPool 2), which will always have 2 threads running)

thheller12:12:25

you then (.submit exec a-clojure-fn)

thheller12:12:46

it will do the queueing for you

thheller12:12:39

strictly speaking there is no consumer, just tasks to be executed

thheller12:12:55

if that works for you

roelof12:12:44

Can this code be made more simpler : (apply concat (reduce (fn[acc it] (if (= (count it) 3) (conj acc (drop-last it)) (conj acc it))) [] (partition-all number number list)))

roelof12:12:09

it's a solution of one of the challenges on 4 clojure

jstew13:12:37

roelof: Which one? I'm on 4clojure, too. Haven't been for a long time though simple_smile

jstew13:12:48

(fn [s cnt] (flatten (map 
 	#(if (= cnt (count %)) (butlast %) %)
 	(partition cnt cnt nil s))))

jstew13:12:20

That's mine simple_smile

roelof13:12:10

@jstew: thanks, At first sight I find it no so good at the readable part

roelof13:12:39

but it looks much like the mine

jstew13:12:47

It's pretty similar. I was really new at clojure when I wrote it, too.

jstew13:12:21

Here's the best solution I found on there: #(apply concat (partition-all (dec %2) %2 %1))

roelof13:12:44

more worst on readabily I find with all the % variables

roelof13:12:51

but that is my oponion

jstew13:12:34

You get used to them. You can always write out (fn [x coll] ...) if it helps you understand

roelof13:12:57

I think I do but thanks for letting me see this

shwx8415:12:04

I am trying to get the project map with merged profiles (that is displayed with lein pprint), during the session, e.g. lein repl, then access the value within the repl. Is there a good way to do this?

roelof16:12:59

@alexmiller: How can I upgrade from 1.7.0

alexmiller16:12:21

if you're using leiningen, then replace 1.7.0 with 1.8.0-RC3 in your project.clj file

alexmiller16:12:46

so your dependency will say "[org.clojure/clojure "1.8.0-RC3"]"

alexmiller16:12:52

[org.clojure/clojure "1.8.0-RC3"]

deas16:12:06

@alexmiller: Any gotchas one should be aware of?

roelof16:12:22

oke, do I have to do something like lein deps or something

alexmiller16:12:30

ok, not that :)

roelof16:12:44

Im learning clojure so sorry for my maybe dumb questions

alexmiller16:12:06

leiningen will download it the next time you run a command that needs it

roelof16:12:09

@alexmiller: thanks, I now see clojure-1.8-rc3 when I do lein repl

roelof16:12:35

I will look if I find things as a beginner in Clojure

roelof16:12:50

the community helps me also a lot when learning

Ivan Fedorov17:12:14

@thheller: that's probably what I was looking for, thanks a lot.

robert-stuttaford18:12:12

@alexmiller: curious, what kind of performance gains does the direct linking produce?

robert-stuttaford18:12:44

i realise that’s a wide-open, fairly unscientific question simple_smile

voxdolo18:12:55

I'm populating some atoms that are def'd at the top level of a namespace (using them as caches) and it seems that after some time its value is lost. Is there a scenario where the JVM (or some other substrate) might deallocate it or garbage collect it?

jaen18:12:49

Well, if you def something it will be re-`def`'d is you load the namespace again.

jaen18:12:01

If you want to avoid that you should look at defonce

ghadi18:12:17

are you reloading the namespace

ghadi18:12:29

that would be the only reason

ghadi18:12:37

and the solution is defonce

ghadi18:12:53

oh snap, sorry jaen

voxdolo18:12:53

jaen, ghadi in development, that's fully likely… and I've not noticed it in deployed environments. you're both probably correct. thank you!

oli18:12:13

@roelof re:41 (defn chop [s n] (let [i (- n 1)] (vec (flatten (partition-all i n s)))))

jaen18:12:15

@ghadi: hahaha, no problem

oli18:12:17

this is fun

juliobarros18:12:18

I'm working on a pedestal app and see that changes in other namespaces (besides service) are not picked up when I recompile them. For example a change in the home-page function works great when it is in service.clj ["/" {:get home-page}] but if I move it to another namespace such as foo.clj and say ["/" {:get foo/home-page}] changes there don't get reloaded. I'm using emacs and a repl, is there a good set up that would cause all changes to get reloaded?

stuartsierra19:12:49

@juliobarros: One possibility is to dispatch your routes to Vars (`#'home-page`) instead of function values. More generally, adopt a workflow that automatically reloads namespaces when their dependencies change. For an example, see https://github.com/stuartsierra/reloaded

juliobarros19:12:38

Thanks @stuartsierra I wish the pedestal template used component by default.

borkdude19:12:32

@cfleming: can I set the indentation rule for a self written macro?

arohner20:12:55

@alexmiller: clarification on the 1.8 changelog: "With this change, clojure.core itself is compiled with direct linking”. Does that mean, “only if -Dclojure.compiler.direct-linking=true” is set, or is clojure.core compiled with direct linking in official releases?

timvisher20:12:32

does (apply dissoc map keys) exist in core or ancillary util function bags?

timgilbert20:12:19

Not sure what you mean @timvisher

timvisher20:12:56

@timgilbert: does the functionality of the above exist as a named function?

timgilbert20:12:38

I guess I'm not sure what you're trying to do, are you dissocing a few keys out of a map?

timgilbert20:12:20

There is not a (dissoc-in) function analogous to (assoc-in) or (update-in)

jr20:12:29

@timvisher: (dissoc map :key1 :key2 …)

timgilbert20:12:51

But you can (update-in nested-map [:key :key] dissoc :child)

timvisher20:12:08

@jr: right. so what if you have [:key1 :key2 … :keyn]? simple_smile

timvisher20:12:34

basically does a version of dissoc exist that accepts a list of keys to dissoc. that's my question simple_smile

timvisher20:12:41

yes i know how easy it is to implement

timgilbert20:12:23

I bet you could get close with (select-keys) but I don't know of a function in core

noonian20:12:25

Well, there is select-keys but it takes the keys you want. I don’t think there’s any core dissoc-keys function.

noonian20:12:32

could just, (apply dissoc m keys)

noonian20:12:58

ah yeah thats what you started with lol

timgilbert20:12:08

Yeah, AFAIK that's about as simple as you can make it

sdroadie21:12:07

Cider updated on Melpa and I absent-mindedly updated to the new version. It wants cider-nrepl 0.10.0-SNAPSHOT, which was fine. But it doesn't recognize the updated version of nrepl (0.2.12) that I also have installed. If I start a lein repl, 0.2.12 is used, but not in Cider. And I can't figure out why. Any ideas?

meow22:12:33

More fun with polygon meshes and a new subdivision algorithm: https://images4.sw-cdn.net/model/picture/625x465_4108313_13235571_1449095437.jpg

codemartin22:12:16

@meow: Keep posting your updates, inspiring to see!

meow22:12:49

@codemartin: Thank you! Glad you like them. simple_smile

rantingbob23:12:29

@meow: That is seriously amazing. How are you doing the rendering? Is there some clojure hook for GL?