Fork me on GitHub

uh. i think electron is totally overkill for everything, but that's just me... it is an incredibly convenient way to go from webpage to desktop application. curious to hear what others would recommend.


i like sublime. I tried atom recently with the integrated repl plugin someone did but i found sublime + terminal was a smoother experience, e.g. atom doesnt have a repl history and the navigation was more like using a text editor than repl.


i know some people dont like sublime because it’s nagware but honestly the way i see it is i’m spending 8 hours a day on it and making a living using it, I can spring the $80.


I’m able to generate java classes from clojure using leiningen, and the classes end up on the classpath when I use the jar in another project. But I can’t import them them properly. Anybody has an idea how to solve that?


Creating jar using lein jar and importing into another project worked for me (Clojure and other used libs needs to be on classpath). Another solution is to use lein install which installs it into local mvn repo. You can then pull it as maven dependency with transitive dependencies resolved.


What exactly is your problem? The classes which you want to use from Java needs to be AOTed, if you want them to have static methods you need to explicitly mark them in :gen-class macro.


The problem is that even though the java files get correctly generated with lein modules install, and the java classes end up on the classpath in the other modules, I can’t import them like other java classes.


Somehow, they are picked up now, maybe because it was a snapshot dependency.


Hello guys… I would like know as you create serializer to validate payload in endpoint using clojure with compojure for example.


@linux.soares Do you mean just “what’s a good way to validate inputs in Compojure” or have I misunderstood your question?


Yes. For example, I need validate payload received in a POST. Example:

POST -> {"name": "Gilmar", "last_name": "Soares", age: 15}

Valid payload: {"name": "Gilmar", "last_name": "Soares", age: "15"}
In payload the difference is a field age is a string not int


I would look at spec for sure as a way to define what the shape of a valid payload is and assert conformance to that spec as one of your first handlers in the route


throw whichever 4xx status code is “malformed input” at your client if validation fails, optionally with some kind of helpful message. 🙂


Here’s the really exhaustive docs for what spec is and why it is that way and how to use it in general:


aaaand a compojure-api wiki page that seems to imply already-existing batteries-included support for either (presumably Plumatic) schema or spec by setting a value for :coercion on your context and then specifying validations on your query params


good night guys ( at least on UTC+1 timezone ) Need one hand to think properly in functional/clojure way: I have one producer the will publish data every X seconds to consumers. The consumers are going to perform some operations based on the data they received and “return” back to the producer the computed value. The producer will receive the computed values, append into internal list and send back to every consumers on next scheduler tick If I had to implement using Java , I would create a shared state and synchronize the access/computation. But I’m trying to do using clojure and would love not to use the ref types/locks primitives. what I thought was to use channels. My solution ( not working as expected ) was: disclaimer: OOP is my background, would love to solve using idiomatic clojure I’ve created one producer with two channels that would be passed into every consumer (input channel/output channel) - the input channel: I’m using tap/mult to dispatch the same messages to every consumer ( cool working great ) - the output channel: response back from consumers that must be saved on producer to be sent next tick

(defn every [seconds callback]
        (t/now) (t/seconds seconds))) (fn [t]

(defprotocol Lifecycle
  (start [this]))

(defrecord Consumer [id producer->consumer-channel consumer->producer-channel]

  (start [this]
    (go-loop []
        (when-let [v (<! producer->consumer-channel)]
            (println (str "Consumer[" id "] received value: " v "\n"))
            (>! consumer->producer-channel (rand-int 3000))

(defn start-consumers [n-consumers multiplexer consumer->producer-channel]
    (map (fn [cid]
         (let [channel (chan (sliding-buffer 1))]
           (tap multiplexer channel)
           (start (Consumer. cid channel consumer->producer-channel))))
              (range 0 n-consumers))))

(defrecord Producer [frequency n-consumers]

  (start [producer]
    (let [consumer->producer-channel (chan (sliding-buffer 1))
          producer->consumer-channel (chan)
          multiplexer (mult producer->consumer-channel)]

      (start-consumers n-consumers multiplexer consumer->producer-channel)

      (every frequency #(go (>! producer->consumer-channel (rand-int 1000)))))))
(start (Producer. 1 2)); every 1 second will send message for 2 consumers what I would like to do ,(I’m not being able ), is on second tick the consumers receive all data that was sent on previous tick and so on ...


basically , in OOP the producer will update internal state and the scheduler will read the internal state every tick


my solution was using atom

(defrecord Producer [frequency n-consumers]

  (start [producer]
    (let [consumer->producer-channel (chan (sliding-buffer 1))
          producer->consumer-channel (chan)
          multiplexer (mult producer->consumer-channel)
          state (atom [])] ; <----------------------------------------------------------- mutable state

      (start-consumers n-consumers multiplexer consumer->producer-channel)

      (go-loop []                                  ;<------------------------------------------------ waiting for consumers response and append into state
        (swap! state conj (<! consumer->producer-channel))

      (every frequency #(go (>! producer->consumer-channel
                                {:state @state   ;<---------------------------------------------------- deref the shared state and passing it to consumers
                                 :value (rand-int 1000) }))))))
I felt so dirty ! I looks like OO


pretty sure there is better way to do this


you can typically replace atom+channel with an agent - an agent has an implicit queue attached to it and represents a concurrency safe mutable state that you can dereference


my main concern basically is design


how to design the code using clojure properly


right, using channels and an atom together is more complex than using an agent directly - in particular you have a loop of async code that exists just to conj things


> in particular you have a loop of async code that exists just to conj things yep