This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-21
Channels
- # announcements (1)
- # aws (18)
- # babashka (5)
- # beginners (72)
- # biff (2)
- # calva (38)
- # cider (2)
- # clj-commons (6)
- # clj-yaml (2)
- # clojars (7)
- # clojure (41)
- # clojure-austin (5)
- # clojure-europe (78)
- # clojure-nl (1)
- # clojure-norway (18)
- # clojure-uk (3)
- # clojurescript (13)
- # component (9)
- # cursive (37)
- # datahike (3)
- # datomic (7)
- # fulcro (7)
- # graphql (3)
- # holy-lambda (2)
- # honeysql (8)
- # introduce-yourself (1)
- # jobs (1)
- # kaocha (1)
- # leiningen (19)
- # lsp (104)
- # malli (5)
- # nbb (8)
- # off-topic (60)
- # polylith (22)
- # portal (2)
- # reagent (24)
- # reveal (1)
- # shadow-cljs (126)
- # test-check (11)
- # tools-build (39)
- # vim (23)
- # xtdb (10)
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.
Docs about this: https://cljdoc.org/d/seancorfield/next.jdbc/1.2.659/doc/getting-started/friendly-sql-functions#table--column-entity-names
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))
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 https://clojure.org/guides/destructuring.I'd pull the anonymous function to its own function. Reads better, easier to isolate, test etc.
thanks @U01RL1YV4P7, it works
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 "'"))
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. ThanksFor 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. -- https://shadow-cljs.github.io/docs/UsersGuide.html#CodeSplitting
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.
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 https://github.com/clj-commons/claypoole 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
pmap doesn't start that many processes. It is "calibrated to suit the number of CPU cores available (https://www.oreilly.com/library/view/clojure-programming/9781449310387/ch04.html)". I have used it a lot as a dirty solution for exactly this use case and it has worked great.
Thanks @U02F0C62TC1 @U02SD8PATK2 — this was helpful!
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
I think it's generally something to avoid as it's confusing to both callers and in the receiving code
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?
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. TIAuser=> (:foo (reify clojure.lang.ILookup (valAt [_ _] (throw (Exception.)))))
Execution error at user$eval1$reify__137/valAt (REPL:1).
null
user=>
heh, is that a kind of value you can read off of a kafka topic without using reify in the consumer?
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).
null
user=>
@U0NCTKEV8 try a non ILookup
my point, for either keywords as functions or using clojure.core/get is that the collection is really in control
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).
null
user=> (:foo (reify java.util.Map (get [_ _] (throw (Exception.)))))
Execution error at user$eval140$reify__141/get (REPL:1).
null
user=>
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 ?
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?) https://github.com/Otann/garden-gnome
: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 `
{:dev
{: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
https://github.com/Otann/garden-gnome/blob/master/src/garden_gnome/watcher.clj#L70
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)
?
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=>
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]])
)
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
“and” saturates on false, “or” on true