Fork me on GitHub
Old account10:04:09

will core.async channels get GCd if unclosed?


Hi, im trying to bring some data into the right shape but for some reason a lot of "nil" value remain and i'm not able figure out why i can't remove them.

(defn git-log [dir]
   (sh "git"
       "-C" dir
       "--pretty=format:'[%h] %an %ad %s'"

(defn apply-schema [data]
  (let [schema [:additions :deletions :name]]
    (filter (fn [x] (not (or (str/starts-with? x "'[")
                             (str/starts-with? x "-")))))
    (map (fn [x] (str/split x #"\t")))
    ;(map (fn [x] (zipmap schema x)))
    (filter #(= (count %) 3))
    (filter #(some? %)))))
these are the functions im using and this is a part of the result:
nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil [17 0 metro.config.js]
[9936 0 package-lock.json]
i also tried to filter for "nil" as string but they still remain 😬 Any pointer what i'm doing wrong here are greatly appreciated ☺️


nvm i guess this is just the println representation 🙈


why is my response status 0 and body "" for a cljs-http? I mean, I see it should be 403 from the server side (django)


Do you have your browser console open?


was this an answer to me? 🙂


if its a browser based repl there often is more information in the console. and i suspect its cors issues which should be reported there in the browser


I don't think there are any repls


I was writing out the response like this

!   2 (defn init-req                                                                       
!   3   [asset-type]                                                                            
!   4   (when-not (string/blank? asset-type)                                                    
!   5     (go (let [response (<! (http/post ""         
!   6                                       {:body {"asset_type" asset-type}}))]                
!   7           (prn 'status (:status response))                                                
!   8           (prn 'resp (:body response))))))    


This code is compiled to JavaScript and run in the browser unless your target is node. If it’s a browser can you open up the dev console?


but it just shows the same thing, 403, some cors error, which i think i know the cause of


Excellent. Then you have solved your issue


have you solved this issue? you aren't seeing anything in cljs because of the CORS issue


if you solve that it will work


what are you talking about??


The CORS issue is your problem


what is excellent, what has been solved? I haven't got an answer and nothing changed, how can you say that's "excellent"?


what excels in this?


that you have identified your issue


no, my problem is that I don't see the same value in clojurescript as the server returns


and you said about the CORS issue > which i think i know the cause of


I asked specifically about this, not something else


right because of the CORS issue


it is the CORS issue


the browser doesn't give you responses to javascript fetches when there's a CORS issue


cljs-http cannot work if there's a CORS issue. The browser's protections prevent it from seeing the response


i am extremely upset and frustrated right now, how can I express this without getting banned? I asked one question and now I am being told that I should just ignore my question because here is another question with an answer, isn't it good that this different question has an answer?


i am literally answering your question


> Note: For security reasons, specifics about what went wrong with a CORS request are not available to JavaScript code. All the code knows is that an error occurred. The only way to determine what specifically went wrong is to look at the browser's console for details.


what should i read from there?


can you share the url you are requesting?


i believe you are seeing this:


(go (let [response (<! (http/get "localhost:3000"))]
      (prn (:status response))
      (prn response)))
client=> 0
{:status 0, :success true, :body "", :headers {}, :trace-redirects ["localhost:3000" "localhost:3000"], :error-code :no-error, :error-text ""}


thanks, you are correct. I mean, obviously you were 100% correct before, but I needed to be told something else. In fact, indirectly, from your answer, I googled just cors and status 0 and then I found that actually there are several reasons that can cause this and cors is just one.


knowing it was not a clojurescript issue helped a lot!

Old account19:04:46

why we need dynamic vars if we can just use def again? Or I miss something?


def creates a new var (shadowing any var with an existing symbol associated to it), alter-var-root and friends mutate an existing var.


the other use case is to simulate dynamic scoping using something like binding.


How can I create a function which wraps its dependency, and doesn't require the dependency untill the function is called?

(defn dynamic-dep-join [a b]
  ;; Imagine this (require) is ridiculously slow
  (require 'clojure.set)

  ;; Now, how do I call the function without requiring a "static reference"?
  ;; The following wouldn't compile unless "by luck" it has been required elsewhere
  (clojure.set/join a b))


i think something like (let [union (requiring-resolve 'clojure.set/union)] (union #{1 2} #{3 4}))

💯 4

an example from clojure/main.clj

  (binding [*print-namespace-maps* false]
    ((requiring-resolve 'clojure.pprint/pprint) report)))

💯 4

requiring-resolve was just what I was looking for. Thanks a lot! Also, congrats on guessing that I meant to use union for the example 😆

(defn dynamic-dep-union [a b]
  (require 'clojure.set)
  (let [f (requiring-resolve 'clojure.set/union)]
    (f a b)))

  (dynamic-dep-union #{:a :b} #{:b :c})
  ;; => #{:c :b :a}


what's the default option for reading browser cookies?


just js interop?


@ashnur are you on Clojure or Clojurescript?


it would be very interesting to see how to read out browser cookies using clojure 🙂


but no, i am in cljs




I'm not an expert at this, but I think there are HTTP conventions for how to read and set cookies using header values. See the Ring docs:


For CLJS, sorry, don't know. Perhaps ask in #clojurescript?


this is a beginner question so i asked here


i don't think ring helps me read browser cookies

David Pham19:04:06

Are there valid reason to use eval when creating macro? I created a macro that defines a function, and I would like to loop over a sequence of argument, but I can’t manage to evaluate my macro without eval.


there may be a reason to use eval in a macro, but it’s really unlikely. do you have a code example? it’s hard to give pointers without more info


I also suspect that you'll be able to make this work without eval. Normally, a macro just returns source code, which will be evaluated normally when the macro completes. I agree with @U7RJTCH6J that a specific example would be helpful :)

David Pham21:04:49

I will try to write one tomorrow! I have to sleep. But basically, a macro (defmacro m [function-name path]) that defines a a function with name function name. Now I have a collection of [function-name path] and I want to loop over that collection and evaluate my macro on each elements.

David Pham21:04:08

Thanks for your help.

David Pham21:04:06

I tried mapv, loop recur, but my issue is I can not finish with a (do (m f_1 p_1) ... (m f_n p_n))


:thumbsup: 🌃

David Pham06:04:31

Here is the example

David Pham06:04:37

(defmacro reg-fn+path
    [fname p]
    `(defn ~(symbol fname)
       ([] ~p)
       ([m#] (get-in m# ~p))
       ([m# v-or-fn#] (assoc-in m# ~p v-or-fn#))
       ([m# f# & args#] (apply update-in m# ~p f# args#))))

  (defmacro reg-fns+paths [fns+paths]
    `(for [[f# p#] ~fns+paths]
       (eval `(reg-fn+path ~f# ~p#))))


@UEQGQ6XH7, maybe something like:

(defmacro reg-fn+path
    [fname p]
    `(defn ~(symbol fname)
       ([] ~p)
       ([m#] (get-in m# ~p))
       ([m# v-or-fn#] (assoc-in m# ~p v-or-fn#))
       ([m# f# & args#] (apply update-in m# ~p f# args#))))
(defmacro reg-fns+paths [fns+paths]
     ~@(for [[f p] fns+paths]
         `(reg-fn+path ~f ~p))))
(macroexpand-1 '(reg-fns+paths [[foo :foo] [bar :bar]]))
;; (do
;;   (my.ns/reg-fn+path foo :foo)
;;   (my.ns/reg-fn+path bar :bar))

David Pham07:04:13

Can you have the arguments be stored in a variable? The [[foo :foo]]?


but you could if you use a regular function


making a function similar reg-fn+path is not usually going to buy you very much. using (foo my-map) isn’t much short than (:foo my-map) or (assoc my-map :foo v) vs (foo my-map v)


but you could create a similar function that’s not a macro like:

(defn reg-fns+paths [fns+paths]
  (doseq [[f p] fns+paths]
    (intern *ns* f  (fn ([] p)
                      ([m] (get m p))
                      ([m v-or-fn] (assoc m p v-or-fn))
                      ([m f & args] (apply update-in m p f args))) )))

(let [fns+paths '[[foo :foo] [bar :bar]]]
   (reg-fns+paths fns+paths)) 


@U7RJTCH6J Nice to see your solution totally avoiding macros 🙂 I've been surprised a few times about the function / macro distinction. Using intern is just a function call. So there's no need for macros, even though you're doing a kind of code generation.

David Pham12:04:14

My issue is it does not work for CLJS 😞


Ah, right. Vars may be Clojure-only. In that case, I think you'll have to use a macro to generate some (do (defn first-fn ,,,) (defn second-fn ,,,),,,)


fundamentally, values generated in clojurescript aren’t available at compile time. there are a couple workarounds, but it depends on the use case.


Hello! I'm trying to use react-moveable ( in a ClojureScript project. I installed the dep by modifying project.clj and adding :npm-deps and :install-deps true. I'm using figwheel for development. In styler.esm.js there is a reference to .`(module$Users$somebody$proj$threat_modeler$node_modules$react$index.Component);` The Component attribute is undefined, and it's raising an error when I'm trying to require react-moveable . The property index.default.Component exists though. I read somewhere ".default" is a es5 thing...anyone ran into something similar before?

David Pham03:04:39

Did you try to build with shadow-cljs?


No, but I will give it a shot!


Moving to shadow-cljs seems to of fixed the error 🙂. Thanks!