This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-25
Channels
- # babashka (9)
- # beginners (56)
- # calva (18)
- # clj-kondo (2)
- # clojars (2)
- # clojure (46)
- # clojure-boston (1)
- # clojure-europe (4)
- # clojurescript (10)
- # css (1)
- # data-science (2)
- # emacs (10)
- # girouette (1)
- # helix (10)
- # jobs-discuss (4)
- # malli (2)
- # off-topic (28)
- # polylith (5)
- # re-frame (4)
- # reitit (8)
- # releases (6)
- # rewrite-clj (1)
- # sci (44)
- # sql (10)
- # tools-deps (31)
Awesome, thank you @smith.adriane for the helpful explanations. That cleared up a lot for me
Is there equivalent to contains? for finding if a value is present in a map?
contains? Returns true if key is present in the given collection, otherwise
returns false.
You can also use Java interop for this:
(.containsValue {:a 1} 1)
;> true
But this won't be portable to other Clojure dialects, like it won't work in ClojureScript. If you want something portable, better stick to using some
.Thank you!
So
(value-contains? {:a 1} 1) => true
user=> (def the-map {:a 1 :b 2})
#'user/the-map
user=> (some (comp #{1} val) the-map)
1
user=> (some (comp #{2} val) the-map)
2
user=> (some (comp #{3} val) the-map)
nil
if you need more than true/false, can use medley.core
. see filter-vals
, http://weavejester.github.io/medley/medley.core.html
why is this test failing :
(def __ '(5 2 4))
(comment
(->>
[2 5 4 1 3 6]
(drop 2)
(take 3)
(map inc))
)
(tests
(__ (map inc (take 3 (drop 2 [2 5 4 1 3 6])))) := (->> [2 5 4 1 3 6] (drop 2) (take 3) (map inc) (__)))
It seems you are calling as a function with ()
is a value. You could try (map inc (take 3 (drop 2 [2 5 4 1 3 6])))) :=
'(5 2 4) is a list. So calling it like () is equivalent to ('(5 2 4)), meaning "call this list as a function", which fails.
({:xAxisValue "MAR 2017", :yAxisValue "NA", :clientYAxisValue 2, :client10p 0, :client90p 0 :shareYAxisValue 6, :share10p 1, :share90p 1}
{:xAxisValue "APR 2017", :yAxisValue 1, :clientYAxisValue 4, :client10p 0, :client90p 0 :shareYAxisValue 7, :share10p 1, :share90p 1}
{:xAxisValue "MAY 2017", :yAxisValue 2, :clientYAxisValue 5, :client10p 0, :client90p 0 :shareYAxisValue 8, :share10p 1, :share90p 1}
{:xAxisValue "JUNE 2017", :yAxisValue 5, :clientYAxisValue "NA", :client10p "NA", :client90p "NA" :shareYAxisValue "NA", :share10p "NA", :share90p "NA"})
user=> (def a '({:x 1 :y 1} {:x 2 :y 2}))
#'user/a
user=> (def b '({:x 1 :z 1} {:x 2 :z 2}))
#'user/b
user=> (map #(apply merge %) (vals (group-by :x (concat a b))))
({:x 1, :y 1, :z 1} {:x 2, :y 2, :z 2})
Hey, could someone help me to configure emacs+cider pprint? I'm currently facing the problem that my emacs freezes when I try to pprint a long string. I tried (setq cider-print-options '(("length" 50) ("right-margin" 70)))
but this does not resolve the issue (or I'm missing something)
Yup, ring’s default jetty web server and most others will have a thread pool to handle concurrent requests. Ring itself though is more like a pattern for working requests at the application level.
Hello, I've set up an http-kit server on localhost:3000 which I'm trying to call from a cljs app on 9090, but I keep getting a Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at
. I have ring-cors
set up, but it doesn't look to me like the "Allow" header is being populated. My app looks like this:
(def app
(-> #'routes
(wrap-defaults site-defaults)
(wrap-cors :access-control-allow-credentials "true"
:access-control-allow-origin [#""])))
Full file https://github.com/RedPenguin101/Notes_Clojure/blob/master/sente_example/ws_server/src/main.clj
curl --head localhost:3000
gives the following, also missing the origin allow
HTTP/1.1 200 OK
Content-Type: application/json
Set-Cookie: ring-session=64c4da9f-5dd2-4b62-9ae6-d1eff297d835;Path=/;HttpOnly;SameSite=Strict
X-Xss-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Content-Length: 0
Server: http-kit
Date: Sun, 25 Jul 2021 15:16:18 GMT
am I not using the wrap-cors
correctly?
Thanks!can you make http://localhost/9090 be http://localhost:9090 ?
Thanks Cora, I made the change (silly typo), but no dice unfortunately.
To be clear, the curl
works fine, and returns as I expect it to, just missing the allow header. It's only when I hit it from the browser that it doesn't work.
▶ curl -X OPTIONS localhost:3000 -i
HTTP/1.1 404 Not Found
Content-Length: 0
Server: http-kit
Date: Sun, 25 Jul 2021 15:48:28 GMT
And
▶ curl localhost:3000 -i
HTTP/1.1 200 OK
Content-Type: application/json
Set-Cookie: ring-session=6b7042cf-4a86-484c-bac2-13a0217f349e;Path=/;HttpOnly;SameSite=Strict
X-Xss-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Content-Length: 17
Server: http-kit
Date: Sun, 25 Jul 2021 15:48:58 GMT
{"Hello":"World"}%
I see, thanks - I guess I need to read more about the preflight request and how they work
Curl will probably always work for preflight
Maybe a late answer... but I had this problem... and after much searching ... I figured out that in the service settings I needed to have ::http/secure-headers {:content-security-policy-settings {:object-src "none"}}
as one of the entries... This is for my pedestal server setup tho... so keep that in mind!! Happy Clojuring!!
Hello, how a LocalDateTime is declared using spec-tools?
@samuel.couto92 that seems to work for me? ^
It works, thanks 😄
If I have an s-expression with metadata that includes line+col information, is there any built in function that can either print out that s-expression putting in line breaks as appropriate? (Alternatively converting the s-expression to a string works.)
Im not sure if there is something taking into account the metadata but for printing human readable s-expressions there is https://clojuredocs.org/clojure.pprint/pprint
@U6JS7B99S Does pprint print things out in a way that can be read back in with, say read-string
?
I believe that there are cases where it doesn't - for example printing a java class instance. It also cannot read back in record instances (It would read them as plain maps)
you may be interested in something like https://github.com/clj-commons/rewrite-clj which can read edn and preserve whitespace.
How would you summon the find-versions
tool talked about https://clojure.org/reference/deps_and_cli#find-versions? I'm trying clj -X:deps find-versions :lib io.github.clojure/tools.deps.graph
and all I get is the error message Function not found: clojure.tools.cli.api/find-versions
1.10.3.855
Is that the prerelease version? The new goodies haven’t made it into a stable release yet
ohhhhh probably not.
weird that it would already be in the official docs...
@cdimara I think Alex was hoping to get to a stable release faster -- but there have been a number of bug fixes on the prerelease side and the Windows scripts also needed to be substantially updated.
(I suspect he also hoped folks read the news article about the changes -- https://clojure.org/news/2021/07/09/source-libs-builds -- where it mentions the prerelease... but it certainly has caused some confusion for quite a few folks based on the Qs I've seen posted here in various channels and on ClojureVerse)
The latest prerelease is 1.10.3.929 I believe (we're on 1.10.3.920 at work). You can see all the release numbers here https://github.com/clojure/brew-install/releases but only stable releases are listed here https://clojure.org/releases/tools (and I don't think anyone would expect folks generally to tie Clojure CLI to brew-install
when trying to figure that out, which is why I'm linking to it).
Oh man I totally read that article. And I assumed it was about features in a current release. Glazed right over the installation part. sorry.
Easy to miss: it's only mentioned on one line over halfway through the article I think...
I'll make the same offer here that I've made in a few other threads: my DMs are always open for any Qs about the Clojure CLI, tools.deps
, tools.build
, and stuff like clj-new
, depstar
, etc 🙂 (which will make sure I see the Q, whereas I might miss it here)

A lot of deps.edn
tooling out there still assumes -A
as the way to invoke things (despite how long there has been a warning to use -M
instead) and a lot of people are still using old CLI installs that don't support -X
so that also adds to the confusion (in the opposite direction).
(and the behavior of -M
changed so old CLI versions don't get the warning for using -A
but can't actually use -M
because it hadn't used to pick up dependencies!)