This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-08
Channels
- # announcements (1)
- # babashka (39)
- # beginners (44)
- # clj-kondo (10)
- # cljdoc (24)
- # clojure (49)
- # clojure-austin (2)
- # clojure-berlin (6)
- # clojure-europe (13)
- # clojure-nl (1)
- # clojure-norway (5)
- # clojure-uk (1)
- # core-async (11)
- # cursive (7)
- # datahike (3)
- # datalevin (2)
- # fulcro (1)
- # hyperfiddle (40)
- # jobs (12)
- # juxt (5)
- # lsp (9)
- # nyc (1)
- # off-topic (27)
- # re-frame (7)
- # releases (3)
- # shadow-cljs (9)
- # timbre (6)
- # xtdb (2)
- # yamlscript (1)
Is there a way to use json_extract in honeysql? to get the clause WHERE JSON_EXTRACT(event, '$.customer_id') = ? AND created_at <= ?
, using mysql. thanks!
Found it!
[:= [:json_extract :e.event "$.customer_id"] :?customer_id]
If someone will need it somedayIt's "just" a function call -- that's generic syntax.
I am trying to be familiar with threading macro, however, I got a wrong use which I couldn't understand.
clj꞉> (->> 1 #(or (<= 0) (>= 9)))
#function[sughiy.notes/eval7979/fn--7980]
clj꞉> (-> 1 #(or (<= 0) (>= 9)))
; Syntax error (ClassCastException) compiling fn* at (.calva/output-window/output.calva-repl:987:20).
; java.lang.Long cannot be cast to clojure.lang.ISeq
😅 Tried to ask the question to gpt4 several times, but none of the result is correct until mentioning the function should be invoked using threading macros.
ChatGPT is like street signs in NYC. They help if you already know where you are going.
I try to use (fn [x] … x …)
instead of the reader shortcut, because it makes errors like this much more obvious, with quite minimal extra text.
> also macroexpand is very helpful in such cases
I just want to say this 🙏
> I try to use (fn [x] … x …)
instead of the reader shortcut, because it makes errors like this much more obvious, with quite minimal extra text.
@U0ETXRFEW, honestly, I still can't understand the error message. 😢 I can see how it went wrong, but I can't understand why.
(-> 1 #(or (<= 0) (>= 9)))
=> (-> 1 (fn [] (or (<= 0) (>= 9))))
=> (fn 1 [] (or (<= 0) (>= 9)))
I got confused again 😅
clj꞉> (macroexpand-1 '(-> 1 (fn [x] (<= 0 x 9))))
(fn 1 [x] (<= 0 x 9))
clj꞉> (macroexpand '(-> 1 (fn [x] (<= 0 x 9))))
; Syntax error macroexpanding clojure.core/fn at (.calva/output-window/output.calva-repl:1093:21).
; 1 - failed: vector? at: [:fn-tail :arity-1 :params] spec: :clojure.core.specs.alpha/param-list
; 1 - failed: (or (nil? %) (sequential? %)) at: [:fn-tail :arity-n] spec: :clojure.core.specs.alpha/params+body
The error message will probably be cryptic still. What I meant is that it is easier spot the error in the code with
(-> 1 (fn [x] (or (<= 0) (>= 9))))
One more thing. If you do your experiments in Rich Comment forms, (comment …)
, instead of at the prompt you will get linter (clj-kondo) help. It will catch both errors and can also help you exercise your ability to translate the compiler error messages. See https://calva.io/rich-comments/ for some more info on this.
I don’t understand the error you get with macro-expanding that form, btw. Let’s hope someone explains it for us! 😃
I found
(macroexpand '(-> 1 (fn [x] (<= 0 x 9))))
would produce the error
but not
(macroexpand '(-> 1 ((fn [x] (<= 0 x 9)))))
It looks like the first one is a wrong usage, so it can't be expanded correctly.(the macro is looking for either a vector which would be the params, or a function name) (fn x []), (fn [])
try (macroexpand-1 '(-> 1 (fn [x] (<= 0 x 9))))
it expands outermost form and makes it easier to see the problem
I have a CSV file containing 100,000 records. My current approach involves executing a GET request for each row and subsequently associating the obtained results. In this scenario, would utilizing 'pmap' be the optimal choice, or does employing asynchronous processing through 'async' offer a more sensible solution?
I would start with pmap and only if the result is not ideal, for example – I need more control over spawned threads – replace it with core.async
what if multiple file has to request 10 * 100000 would cause an issue right ?
does pmap takes all resources (memory ) and might get crashed ?
pmap uses future under the hood. And future runs using thread pool https://github.com/clojure/clojure/blob/clojure-1.11.1/src/jvm/clojure/lang/Agent.java#L53C48-L53C48
note that there is only one threadpool for entire application.
also general recommendation is to use pmap only for computational extensive functions. http request function is only waiting for the response so switching from map
to pmap
will not give you a very significant boost
earlier I was doing it with map for 100000 request, which took 4 hr, but applying pmap is reduced to 16mins, So I am worried where this is consuming more resources and might crash for multiple request!
Yeah, if you're calling an external API for those records you should be careful with pmap; usually you want to have a bit more control over the number of concurrent requests so you don't run into weird rate limiting behavior from whatever API you're using
https://github.com/clj-commons/claypoole
Claypoole is a nice library for controlling the number of concurrent requests without going all the way to core.async
@UFTRLDZEW, Just one question, What happens if use pmap in such cases
I don't know enough about your application to answer that question.
http://brunov.org/clojure/2014/05/14/throttler/
If you need to enforce rate limits on your function you can use a library like throttler
.
in generally I am asking, does it may call out of memory ?
If I had to guess why you're seeing such a speedup from pmap
, I think it's because there was a "long tail" of a few requests that took a long time to run, and were blocking the others because they were running sequentially and had to finish before the next could start.
yes exactly
pmap is bounded by clojure's chunk sizes and the number of cpu cores on your system, so I don't think your primary concern should be running out of memory - it won't give you hundreds of concurrent threads. See the explanation at the end of this page: https://clojuredocs.org/clojure.core/pmap
does your API provide a bulk request/update interface. i think most APIs are not going to respect an app that is hammering them. you'll run into problems with the API rate limiting you, or just outright banning you. if the service you are using is acting like a thin layer over a DB, which it sounds like it is in your case, then they should have bulk API endpoints. working with something like that will be a lot simpler.
no, it doesn't know
extensions are stored mostly with the protocol, not with the record