Fork me on GitHub

I poked my head out of the backend for two seconds and the front end just dumps all over me. I'm turning a command line app into a SPA. Right now it makes rest calls to a service I don't own and I get a response without issues. But when I try to make those rest calls from the frontend I get nothing but trouble


so i'm guessing I have to make the frontend calls to a backend service I own that makes the rest calls or whatnot


an extra layer of coordination


yeah- likely you are running into xss issues?


getting the message No 'Access-Control-Allow-Origin' header is present on the requested resource


my google foo wasn't very good last night. just now I searched for "clojurescript CORS" I see a google groups post from 2014 where someone had the same issue I was 😁


also, for almost anything, you can just use the javascript answer


the translation is trivial


(or in jvm clojure, the java answer - though that can be trickier with cases involving inheritance)


that's true, googling "javascript cors" also provided helpful results


Any clue what's wrong here? Desired function call fails. Function body succeeds.

(def ^:dynamic *global-transient*)
(defn test []
  (assoc! *global-transient* ; Side effect, only.  update! (?)
          (conj (or (get *global-transient* "keyString")
                {"keyString" "replaceMe?"})))

edit-server.core> (let [*global-transient* (transient {})]
ClassCastException clojure.lang.Var$Unbound cannot be cast to clojure.lang.ITransientAssociative  clojure.core/assoc! (core.clj:3259)
edit-server.core> (let [*global-transient* (transient {})]
                    (assoc! *global-transient* ; Side effect, only.  update! (?)
                            (conj (or (get *global-transient* "keyString")
                                  {"keyString" "replaceMe?"})))
#object[clojure.lang.PersistentArrayMap$TransientArrayMap 0x38327a4e "[email protected]"]


let bindings and vars are not interchangable


sorry for the wrong answer before, I misread


not using the return value of assoc! is incorrect - it sometimes accidentally works, but it is guaranteed to break when certain size boundaries are crossed


@bschrag but the specific problem here is just due to how values are resolved - a let binding shadows a var (that is, hides its name in code compiled within that scope), but does not replace it or fill it in


what happens when you don't use the return value of assoc!

user=> (let [t (transient {}) _ (apply assoc! t (range 32)) m (persistent! t)] (map m [0 2 4 14 16 30]))
(1 3 5 15 nil nil)


simpler example of what went wrong in the original code:

+user=> (def x)
+user=> (defn get-x [] x)
+user=> (let [x 2] (get-x))
#object[clojure.lang.Var$Unbound 0x30b19518 "Unbound: #'user/x"]


@noisesmith So, this is wrong, too (but different):

edit-server.core> (def ^:dynamic x 2)
edit-server.core> x
edit-server.core> (defn get-x [] x)
edit-server.core> (get-x)
edit-server.core> (let [x 1] (get-x))
I had better study up on Clojure scope. (It's not Common Lisp...) 😳 Thanks!


@bschrag you can change a dynamic binding in a scope with binding


when a form is compiled, the actual value being captured is what's important (whether a var or local binding or whatever), not the name


Hi everyone! I have the following code:

(for [elem1 list1]
  (for [elem2 (.getElem2 elem1)]
    (for [elem3 (.getElem3 elem2)
          :when (...)]
It works perfectly except when the
statement does not match. In this case I ended up with list like:
(elem3-1 elem3-2 (()))
because for always return empty list. How can I eliminate these empty lists?


I tried doseq but it returns nil and I can't came up with an idea how I can store elements from it


@nmax (for [elem1 list1, elem2 (...), elem3 (...) :when ...] elem3)


@rauh Thanks, it works!


Are there some rules dictating when CIDER responds to a Java compiler error by highlighting source code with that nice red underlining? I frequently find myself confronted with cryptic error messages and only a stack trace to work with.


Hey guys any advice for the best unit test CI tool?


Does anyone have any good resources to understand the Java/servlet stuff works (more specifically, the things that would help me understand the parts that ring uses)?


I don’t have a good doc handy, but it’s more accurate to say the servlet uses ring - ring implements something the servlet uses to create a web http handler


the servlet container decides what the route and port are, the ring app decides how to handle a request


@shaun-mahood do you have a specific problem or just looking for an overall view?


Mainly looking for an overall view, though the specific thing I eventually want to be able to do is understand enough to understand or translate Java examples dealing with authentication and security.


But having never dealt with the java web stack (or java) outside of using clojure I definitely am missing some basics.


you may find the docs at useful. see esp. the bits about defservice.


also, keep a copy of the Java Servlets spec handy. It's quite readable.


np. warning: to use servlets you must use gen-class afaik. but the gen-class docs are notorious. if you find them a little indecipherable just ask.


Hey guys, I'm searching for some advices on separing my application logic from database interaction, do you recoment any article or text where I can get tips about that? I'm creating an app with clojure and postgresql, but I should use less sql as possible, so my ideia is to have a function that query a complete table and other functions that use this data will always receive it as an argument, then I will be respecting the rule "call the same function with exactly the same arguments should always return the same results". Is that correct?


For apps where disentangling the persistence logic from the application logic is a relevant consideration, I’ll reach for one or more protocols which describe the database interactions required. For example, a UserDatabase protocol might have list-all-users find-user and update-user fns.


@pitalig Normally, you'd want to figure out how to model your data in Clojure (which will probably look different from a normalized sql table structure), and then work with that data model everywhere in your code, and only deal with sql when you're loading or storing that data model.


Thank you guys!