Fork me on GitHub
Ivan Koz07:01:15

can somebody explain why do we have two invoke for the functions, and why do we call static function from the instance method.

    public Object invoke(final Object coll) {
        return invokeStatic(coll);


interesting question ... in my head a function is just a function, like sinus or cosinus in math, very static 🙂


@nxtk I am guessing you are talking about the JVM byte code produced when the Clojure/Java compiler compiles a Clojure function? Or is that code you gave an excerpt from a Java source file inside the Clojure implementation somewhere?


and i expect jit can cut a lot of corners if it has the inside information about the behavior being static


hey guys, probably super easy/quick for some of you. r/take-while is making my code not to run in parallel. as soon as I removed the take-while the code start doing the “computation” into different threads ( fork-join executor ) why take-while is doing that ? ( is that correct assume the problem is with take-while , or any other issue with my code )

(def ts (atom #{}))
  (defn stop? [_]
    (< (rand-int 100) 90))

  (defn conjj [a b]
    (swap! ts conj (.getName (Thread/currentThread)))
    (conj a b))

  (r/fold 2 (r/monoid conj vector)
          (r/take-while stop? (into [] (partition-all 2 (take 200 (range)))))) ; => running on just 1 thread
  (println "n threads" (count @ts))
  (reset! ts #{})

  (r/fold 2
          (r/monoid conj vector)
          (into [] (partition-all 2 (take 200 (range))))) ; => running into multiple threads

  (println "n threads" (count @ts))


Yeah , using from reducers @kulminaator


Sorry, wasn’t explicit , r is a alias for the reducers


Don’t know why is not doing in parallel


wouldn't it be enormously unpredictable if it would do it in parallel ?


or maybe i understood you wrong ... you would expect it to do it's work in parallel per partition ?


I thought it would do in parallel ... but maybe I do not understood properly


Thought the reducers would try to do it in parallel and combine later on


the parameter that you ignore in your stop function


is one partition of your initial collection


if you handle those in parallel and decide to stop at any point ... i would think you get different results every time you execute this


(i'm just confused by what you are trying to achieve, sorry)


did you expect stop? function to be fed individual values from the initial collection ?


sorry @kulminaator, I had an emergency at morning. basically what I want to dois to read a huge file, process chunk of lines and as soon as I found what i’m looking for in the line, stop the process


how can I accomplish that in clojure way ?


when stuff get's into i/o related latencies and threading i have reached out to core/async. maybe your case can just be solved by storing the results and checking need to stop in an atom ? i dont think multithreading will help you much there to be honest, unless your check is very cpu expensive reading from disk will always be slower than simple logic on the cpu.


every line I have to do some cpu intensive task, like cryptografic hash.


so , basically, my idea was to fetch in streaming the file and send to threads to process, stop as soon as I found what I’m looking for


but I’m not know how to do that ( I did in java through executor service with blocking queue. so I had 8 fixed thread consuming the queue )


Looking to start a project that utilises a http and websocket client in both clj/cljs. I've looked into several implementations on the clojure side, http-kit, sente, aleph and all are either really complex or only direct to a server solution which is not what I'm after. The cljs side of things is a bit more straightfoward as would make sense given that the frontend domain is far more client orientated. Would anyone have advice for what is the best approach?


What issues did you find with Sente?


If I have a primitive mutable local in a deftype , how can I set! it? I'm trying this but I get an error:

(deftype TypeA
    [^{:unsynchronized-mutable true :tag int} a]
  (foo [_ new-val]
    (set! a ^int new-val)))
I get an error: Must assign primitive to primitive mutable: a I thought the type hint in new-val would be enough for the compiler to determine that new-val is a primitive int?


but if you do (int new-val) instead it works ?


you're right, it works!


So I understand, this is because the reader interprets integer literals as Longs, not Integers, and needs explicit conversion to reassign to a variable tagged int, right?


I'm not sure if that's the reason... new-val could be an int after all. I'd just need to cast it before calling foo, or obtain it from an interop method call.


But anyway, what I'm expecting semantically from the code above is a cast (what should the code above do if passed something other than an int besides a ClassCastException?) So I guess having an explicit cast is the right answer. I still don't know why the original code won't work.


maybe "gods of immutability" are just trying to prevent you from commiting a sin

😆 2
😅 2
☝️ 1

given a multimethod and a dispatch value, is there a way to find out in which namespace the defmethod was defined?


I tried something similar a while ago and didn't have much luck. You can get the function which backs the multi method, and it might have a name which indicates the namespace