Fork me on GitHub
quan xing04:10:57

I use the next.jdbc insert data with mysql. but the column's name is Rank . The Rank is mysql function. So I call in jdbc/insert! insert map to msyql show Execution error (SQLSyntaxErrorException)

(jdbc/insert! conn :test {:ID "ID" :Rank 123})
and generate insert sql is :
insert into test (id,rank) values ("id", 123) 
The rank is mysql's function, so It's output SQLSyntax , how can I generate SQL like this:
insert into test (`id`,`rank`) values ("id" 123)


Look at :table-fn and :column-fn in the documentation and the quoted namespace.

quan xing05:10:57

Ok, I got it. Thanks.

Abhi Saxena04:10:28

Hi All, I have a vector (of vectors) that looks like: [[:a 560] [:b "09/22/2018"]] How can I destruct it to generate below string: a = 560, b = '09/22/2018' I am able to achieve this with below code by I have to use destruction to generate this, here values in the input vector

(join "," (map #(format "%s = %s" (name (nth % 0)) (nth % 1)) values))

Martin Půda05:10:57

But there are no apostrophes around "09/22/2018":

(->> [[:a 560] [:b "09/22/2018"]]
     (map (fn [[kw v]] (format "%s = %s" (name kw) v)))
     (s/join ", "))

=> "a = 560, b = 09/22/2018"
You can also read


I'd pull the anonymous function to its own function. Reads better, easier to isolate, test etc.

👍 1

Nested destructuring is ugly and hard to read, but it does work.

(let [[[_ a] [_ b]] [[:a 560] [:b "09/22/2018"]]]
  (str "a = " a ", b = '" b "'"))

👍 1
Rambabu Patina11:10:54

Hi Team, I need help with shadow-cljs. I want to exclude particular library while building. The shadow-cljs.edn looks such as

:app {:target :browser
   :modules {:shared {:entries []}
             :other {:entries ..}
My assumption is if the entries is empty (i.e []) then bundling all dependencies in public/shared.js file. I want to exclude a library which is not required at client side. I appreciate your time. Thanks


For questions specifically about shadow, I definitely suggest asking in #C6N245JGG. @U05224H0W is absolutely amazing with providing thorough (and usually very fast) support. Your assumption about {:shared {:entries []} ... } is pretty far off. > You can leave the :entries of the :shared module empty to let the compiler figure out which namespaces are shared between the other modules. -- So with this config, shadow will follow the entry points defined by your other modules in order to calculate for you what is shared. The result of that calculation will be included in the shared module.

👍 1

Hey team — Say I have a collection, and I want to run an an http request per item What would you think if I wrote

(pmap fetch-thing coll)
pmap is so good, but I am a bit wary about futures and what this could mean for the efficiency of the system. So maybe another way to phrase the question: How should I think about the efficiency tradeoff of pmap? If I have a system with 1GB of ram for example, at what point will these pmap calls take me out? Would you think about this differently?


you can have a look at if you want a bit more control the hard part of this problem is usually handling network failures core async's pipeline could help too

❤️ 1

pmap doesn't start that many processes. It is "calibrated to suit the number of CPU cores available (". I have used it a lot as a dirty solution for exactly this use case and it has worked great.

❤️ 1

Thanks @U02F0C62TC1 @U02SD8PATK2 — this was helpful!


pmap is simple but suffers from head-of-line blocking

👍 1

what is a good way of allowing both namespaced and un namespaced keys as input to a function? Or would it be bad style to want such a thing?


I don't mean a mix but allowing both :foo/foo and :foo. Specifically I would destructure an input map

Alex Miller (Clojure team)14:10:05

I think it's generally something to avoid as it's confusing to both callers and in the receiving code

Alex Miller (Clojure team)14:10:33

but you can do so like:

(let [{unfoo :foo, :foo/keys [foo]} m
      the-real-foo (or unfoo foo)] ... )


I’m looking for a function like filter, but it should stop early when it finds the first match. Or is it okay to just do (first (filter pred collection)) because of lazy evaluation?


you are correct about the lazy

👍 1

or some with when:

(some #(when (pred %) %) collection)


hi 🙂 Is there a value you can pass to a keyword that could cause an exception?

(:foo some-value)
I tried string and integers. Context: I’m inside a Kafka consumer and I have a message that my consumer could not handle. Normally the data I care about is inside the message and I get it like this
(:data message)
The Kafka partition, offset, etc are normally pulled out of the message like this
(:meta message)
I’m wondering if I can safely do these two operations when logging my consumer’s failure ---- or if applying :data and :meta could fail, killing my Kafka consumer. I suppose I could wrap that itself in a try if the answer to the original question is “Yes”. But if the answer is “No there’s no such value that could cause a keyword to throw”, that’d be nice to know. TIA


user=> (:foo (reify clojure.lang.ILookup (valAt [_ _] (throw (Exception.)))))
Execution error at user$eval1$reify__137/valAt (REPL:1).


heh, is that a kind of value you can read off of a kafka topic without using reify in the consumer?


dunno, my point it is depends on what message is, not so much the keyword


if you want to be safe, use get


I mean, get will do the same thing


destructuring is also ok. using keyword syntax is not the same as get and it has bitten me in the ass a few times.


user=> (get (reify clojure.lang.ILookup (valAt [_ _] (throw (Exception.)))) :foo)
Execution error at user$eval1$reify__137/valAt (REPL:1).


@U0NCTKEV8 try a non ILookup


that part is dynamic, you don't really know the param type being given to :foo or get


my point, for either keywords as functions or using clojure.core/get is that the collection is really in control


and it can do whatever it likes


so that is what you need to know about if you what to see if it throws or not


what what "message" is in the question is not really specified


I think what matters here may be what the desired behaviour is on the lookup when it's in a fail case. ignore and process message, or throw + do error handling stuff?


doing something like if-let on a get that returns nil is pretty convenient, compared to keyword lookup that throws cus you gave it something like a string or something else bad


but, for the very first question (are there values that make keyword lookups throw), yes, and actually it's most values that do that, but typically you restrict the types you use in a clojure program to just a handful that do work with keyword lookup


user=> (get (reify java.util.Map (get [_ _] (throw (Exception.)))) :foo)
Execution error at user$eval1$reify__137/get (REPL:1).
user=> (:foo (reify java.util.Map (get [_ _] (throw (Exception.)))))
Execution error at user$eval140$reify__141/get (REPL:1).


i'm pretty sure (:foo "my string") doesn't work


i'm not sure what values keyword lookup doesn't like, but i have run into them a few times and they make very weird errors (just because they are unexpected)


there is some complicated stuff with keywords as functions, the compiler will insert inline caches for those because they might be record field lookps


maybe i shouldn't be so worried about them. just tried a lot of different test cases i thought should fail and they didn't. makes me very curious as to the ones i ran into. maybe they are specific to yada or something


Hey folks, I've seen recently following formulation:

(fn [report-instance {:account/keys [id]}]
             <some code...>)
It is an action inside a button in fulcro but I don't understand what does the params definition mean and how does this work? Why can I define report-instance AND {:account/keys [id]} ? I suppose that report-instance and id are coming from the button, or?


that's a function that takes 2 arguments. The first is bound to report-instance inside the function body and the second arg is destructuded (because it's assumed to be a map) so that id is bound to the :account/id key in the map. Is this in clojurescript?


yes it is in cljs. ok so there isn't something special. I've tried to delete a form with a "delete-button". But there are only following functions: form/delete!, form/delete-entity. In form/delete! I have to provide [this id-key entity-id] whereas this is report-instance I guess and id-key is the uuid from my account. But what is entity-id and where to get it?


I'm not sure I know what form/delete-entity is ... you might have better luck asking in #C68M60S4F ?


thanks so far, I will do that!

👍 1

Somebody can help me how to possible add this configuation to deps.edn? (I rewrite my lein project to deps.edn.. and is that possible?)

:garden {:builds [{;; Source path where to watch for changes:
                   :source-path "dev/sample"
                   ;; The var containing your stylesheet:
                   :stylesheet  sample.styles/screen
                   ;; Compiler flags passed to `garden.core/css`:
                   :compiler    {:output-to     "resources/public/screen.css"
                                 :pretty-print? true}}]}


I added as extra-deps `

 {:extra-paths ["src/dev"]
  :extra-deps  {garden-gnome/garden-gnome {:mvn/version "0.1.0"}}}
but the configuration part.. where is the right place?


Looking at the source code, it looks like you can put your config into a garden.edn file in lieu of having a project.clj

👍 2
🍻 1

true, I totally forget.


I didn’t use a lot time ago in this way. Thanks!


Happy to help 🙂


For finding the maximum item in a seq, is there any reason to prefer one option over the other: (reduce max my-sequence) vs (apply max my-sequence) ?

Alex Miller (Clojure team)23:10:21

I think the former is more direct. The latter is going to gather up all the inputs to make one big function call, which is going to walk through everything anyways. The reduce has a lot of different optimizations built in too depending on what my-sequence is


Clojure 1.11.1
user=> (apply max [])
Execution error (ArityException) at user/eval1 (REPL:1).
Wrong number of args (0) passed to: clojure.core/max
user=> (reduce max [])
Execution error (ArityException) at user/eval3 (REPL:1).
Wrong number of args (0) passed to: clojure.core/max


user=> (apply max 0 [])
user=> (reduce max 0 [])

Bob B23:10:09

personally, apart from performance implications, I generally prefer to use reduce when I think of the operation as logically a reduce (typically operating on two items at a time), and apply when using a collection as function arguments (e.g. (apply partition [2 [1 2 3 4]]) )

Sam Ritchie01:10:32

In #C01ECA9AA74 I switched to apply for examples like this because 1. Certain functions like * that I would usually reduce with can short circuit and stop consuming the sequence if they hit a zero 2. The multi arity version reduces internally anyway But I’m curious about @U064X3EF3 ‘s comment here about gathering up all inputs


Short circuit on zero is intriguing


(defn saturates [f v] (fn [a x] (let [r (f a x)] (if (= r v) (reduced r) r))))

Sam Ritchie01:10:57

“and” saturates on false, “or” on true


I would always throwing in a starting element in both