This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-19
Channels
- # announcements (3)
- # babashka (42)
- # beginners (84)
- # calva (3)
- # cider (13)
- # clj-kondo (9)
- # cljs-dev (6)
- # cljsrn (32)
- # clojure (47)
- # clojure-argentina (4)
- # clojure-france (2)
- # clojure-spec (17)
- # clojure-uk (15)
- # clojuredesign-podcast (4)
- # clojurescript (41)
- # conjure (53)
- # cursive (16)
- # data-science (5)
- # duct (1)
- # emacs (11)
- # events (1)
- # exercism (3)
- # fulcro (48)
- # graalvm (20)
- # graphql (1)
- # joker (3)
- # kaocha (2)
- # malli (2)
- # meander (6)
- # pathom (3)
- # planck (18)
- # rdf (3)
- # re-frame (14)
- # ring-swagger (1)
- # shadow-cljs (15)
- # specter (1)
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
"log"
"--pretty=format:'[%h] %an %ad %s'"
"--date=short"
"--numstat")
:out
(str/split-lines)))
(defn apply-schema [data]
(let [schema [:additions :deletions :name]]
(->>
data
(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 ☺️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)
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 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
have you solved this issue? you aren't seeing anything in cljs because of the CORS issue
what is excellent, what has been solved? I haven't got an answer and nothing changed, how can you say that's "excellent"?
no, my problem is that I don't see the same value in clojurescript as the server returns
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?
> 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.
(go (let [response (<! (http/get "localhost:3000"))]
(prn (:status response))
(prn response)))
#object[cljs.core.async.impl.channels.ManyToManyChannel]
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.
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}))
an example from clojure/main.clj
(with-out-str
(binding [*print-namespace-maps* false]
((requiring-resolve 'clojure.pprint/pprint) report)))
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)))
(comment
(dynamic-dep-union #{:a :b} #{:b :c})
;; => #{:c :b :a}
)
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: https://github.com/ring-clojure/ring/wiki/Cookies
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 :)
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.
Thanks for your help.
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))
Here is the example
(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]
`(do
~@(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))
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))
Nice! :)
Thanks
@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.
My issue is it does not work for CLJS 😞
anyways :-9
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 (https://github.com/daybrush/moveable/tree/master/packages/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?
Did you try to build with shadow-cljs?