This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-19
Channels
- # announcements (37)
- # aws (6)
- # babashka (12)
- # babashka-sci-dev (16)
- # beginners (83)
- # biff (10)
- # cider (14)
- # cljdoc (26)
- # cljs-dev (20)
- # clojure (123)
- # clojure-czech (9)
- # clojure-europe (26)
- # clojure-nl (4)
- # clojure-norway (20)
- # clojure-spec (7)
- # clojure-uk (6)
- # clojured (14)
- # clojurescript (28)
- # cursive (5)
- # datalevin (8)
- # datomic (3)
- # duct (6)
- # emacs (26)
- # events (2)
- # fulcro (7)
- # gratitude (1)
- # holy-lambda (19)
- # integrant (1)
- # jobs (2)
- # leiningen (8)
- # lsp (7)
- # nyc (1)
- # pathom (70)
- # re-frame (8)
- # reagent (15)
- # releases (1)
- # sci (8)
- # shadow-cljs (117)
- # testing (5)
- # tools-deps (11)
- # vim (5)
@swlkr I think the automation for https://todayinclojure.com/ has stalled, the page has not updated since 16th April.
Is this why? 😉 https://swlkr.com/posts/clojure-isnt-for-me/ And apparently the tool is written in janet and ruby! Interesting. But you all probably knew that and I'm not being useful.
Perhaps slightly more useful, I just wanted to note that the GitHub automation still seems to be working. In other words, if anyone is really desperate to read it you can just read the index.html that is on the master branch. But if you also use a HTTP server then also the styles get loaded correctly: E.g.:
git clone -b master
cd todayinclojure-static
python3 -m http.server 8080
... and click on the localhost link. git pull
to update every day. 🙂
(Sorry for not knowing an equally compact Clojure HTTP serve snippet).
A nice little tool indeed! (Thanks @swlkr, if you're around)I think since Java 11 you can do
java -m jdk.httpserver -p 8080
And since Java 18
jwebserver -p 8080
Hello all, what is vulnerability about CVE-2021-43138 and org.clojure/core.async
? I could not figure out what is the .jar
to replace.
I found
but it appears to be about https://github.com/caolan/async which is a javascript library for async programming
it is not unusual to have false positives in the nvd checkers - if you are seeing that, you should file an issue so they can improve (I've done this in the past). might depend which tool you're using where to report that
at https://github.com/jeremylong/DependencyCheck/issues (used by nvd-clojure), you can file an issue - they have a template for false positives
Hi, I am trying to understand a strange behaviour of Safari on iOS together with Sente and Transit which sometimes incorrectly serialize messages: https://orgpad.com/img/Cb1U8vwilBZ7ozpDkuFplV/download?token=CPD6Xt0O5Lqa4IXGP2reS_
In the second message, :orgpage/id key is replaced by ^1.
The message itself is build in the code using map literal like this:
And the strangest thing is that when I run (js/console.log (pr-str message)) before sending it with Sente+Transit, the bug disappears.
❯ echo '[:orgpage/ops {:orgpage/id 1 :ops/op-id 2 :ops/window-id 3} {:orgpage/id 2 :ops/op-id 3 :ops/window-id 75}]' | jet -i edn -o transit
["~:orgpage/ops",["^ ","~:orgpage/id",1,"~:ops/op-id",2,"~:ops/window-id",3],["^ ","^1",2,"^2",3,"^3",75]]
In the second message, :orgpage/id is replaced by ^1 and when deserialized, I get nil key instead.
:orgpage/id is not repeated in the message.
Btw running (js/console.log message) does not fix the issue.
How it works, at least the way I see it from your screenshot:
• You create a writer, write a message, and send it to a client
• The client receives the message, creates a reader, reads the message, and discards the reader - thus discarding all information on already seen keys
• You send a second message in the same way, reusing the writer - which at this point knows about the seen keys
• The client creates a new reader and fails on ^1
because there are no keys that it has seen before
Why js/console.log fixes that?
No clue, I'd have to tinker with a minimal reproducible example to figure that out.
Maybe you have some strange custom printers set up. Maybe your js/console.log
is overwritten with something custom that does something relevant. Maybe your message
has lazy collections in there and somehow that affects things (maybe unrolling those collections side-effects)`.
This is how I am using transit with sente: on the server:
and on the client:
not sure whether transit-packer is somehow reused on Safari, sounds plausible
But that's not a minimal reproducible example. :) Can you create a repo with all the components and a description of how to run it that would exhibit this behavior? I'm looking at the Sente code right now and it's a bit strange. On the one hand, I'm using it in pretty much the same way and have been using for a few years without noticing any issues. On the other hand, my memory of Transit internals must be wrong because they way Sente memoizes readers and writers is inconsistent and should lead exactly to the issues you see. I'll look a bit more into how exactly Transit does its caching, but you should still come up with an MRE. Even if I don't figure it out, it'll be incredibly useful when reporting a bug for Sente.
For the defn form, what’s the recommend place to add meta data, place a or b?
(defn (place-a) foobar (place-b) [] body)
For a function with multiarity,
(defn foobar
([] ...)
([x] ...))
How do we annotate the return type when the two arities have the same return type?for the form
(defn name doc-string? attr-map? ([params*] prepost-map? body) + attr-map?)
why isn’t it be
(defn name doc-string? (attr-map? [params] ...)
actually dunno what exactly
(defn name doc-string? attr-map? ([params*] prepost-map? body) + attr-map?)
means. regarding the attr-map? part.https://clojure.org/reference/java_interop#typehints > For function return values, the type hint can be placed before the arguments vector:
I was referring to the
(defn name doc-string? attr-map? ([params*] prepost-map? body) + attr-map?)
The format is mysterious, why two attr-map? in the above form?the latter attr-map? is an optional thing which nobody ever uses, except one library
The official doc has an attr-map,
Usage: (defn name doc-string? attr-map? [params*] prepost-map? body)
(defn name doc-string? attr-map? ([params*] prepost-map? body) + attr-map?)
Sounds like the attr-map place is the recommended one.Speaking of metadata it seems that this is wrong?
(import '[org.apache.jena.graph Node NodeFactory])
(defn ^Node uri->node ;; Type hint for Jena Node instances
"Create a URI node from `uri`."
[uri]
(NodeFactory/createURI uri))
I've always placed type hints for return values between the defn
and function name, but the latest clj-kondo says this is wrong:
Prefer placing return type hint on arg vector: Node
clj-kondo(non-arg-vec-return-type-hint)
You can find more info in this issue, why: https://github.com/clj-kondo/clj-kondo/issues/1331
Fair enough. So it seems like this recommended way for Clojure:
(defn var->node
"Create a variable node from `var`."
^Node [var]
...)
It should be either
(defn var->node {:tag Node} [var],,,)
or
(defn ^Node var->node [var] ,,,)
I've got a web-service A that depends on a second web-service B. A holds a connection to B and A exposes a REST interface to the world using compojure as the interface library. The question is how to manage the different servers - one can start or stop A and connect to/disconnect from B. What is the preferred way of ensuring that if A is running, a connection to B is available and if A shuts down, the connection to B gets closed?. I know that Component and Mount are two libraries that help to handle these sorts of issues, but I've no experience in using them and certainly no experience to choose between the two. I've also seen a couple of "roll your own" solutions using atoms and delays to work with. Does anyone have any advice for how to structure the code and which (if either) of Component/Mount to use?
I don’t know your use case, but if you do some operations which needs to be done one by one consider use async
channel
. You can add there into queue requests without waiting for response and you will be sure there will be no parallel request.
I did this for bookkeeping and warehouse things.
It is not directly response for your question, but maybe can open your mind for other solution
you can’t control connection A<->B, so I would try to send something to the third party service and if connection doesn’t work, then reconnect it. Without any extra code like component.
has there been any interest in map literal shorthand notation, similar to how javascript's https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#new_notations_in_ecmascript_2015 works?
(def a 1)
(def b 2)
(def c 3)
;; current
(def m {:a a :b b :c c})
;; literal shorthand
(def m {a b c})
that's a great point, @U08JKUHA9, I didn't think about that lol
In javascript I guess it is the commas. Would it be bad to make them significant in this one case?
https://clojureverse.org/t/shortand-clojure-syntax-for-properties-on-hashmaps/1918/21
if we were in another lisp (common lisp, racket, etc), adding a reader macro would handle this: #kw{a b c d}
-> {:a a :b b :c c :d d}
whereas #s{a b c d}
-> {'a a 'b b 'c c 'd d}
you could add a reader macro for this in clojure. #kv [a b c d]
could return a hashmap
the ambiguity of using the map literal + even number of forms is the real problem
yeah, and that would be an extreme change in the informal spec that clojure abides by (commas are whitespace)
It is a potentially breaking change, though the codebases where that would be breaking are kind of bizzare.
my understanding is that there is no chance to get a breaking change into the reader, and almost no chance to get an extension to the reader, especially for something that is just a shorthand or convenience. There are also lots of different design choices that make this unlikely to land in core. (same thing for dissoc-in collapsing empty subtrees, nils, empty maps, etc). So i would add a macro to your own codebase and see if you like it. But would basically not expect any movement from core
yeah, that seems like an accurate assessment. thanks for the clojureverse link!
if you make a macro and use it in your codebase for three months, post on http://ask.clojure.org and give the problem you solved, why it was great, and ask if something like that could go into core. If it is based on real world usage and solves a problem you will provide evidence. If its just off the cuff “wouldn’t it be nice if …” it will not lead anywhere most likely.
hah no, I was more just thinking out loud and wondering what the communities thoughts on it were
This isn't really the kind of thing a macro would be satisfactory for, because requiring something all over the place is a pain in Clojure. Writing it out the long way would usually be faster than: 1. checking the requires of the namespace you are in 2. adding the macro if needed, 3. going back to where you were (I know some editors are able to help with this sometimes, but it is not reliable IME.) So I don't think there is a way to make this better without core support.
if you made it a reader macro, you wouldn't need to require it everywhere. just set up your data_readers.clj(c) in the root of your project
For per entry, a suggestion:
#isak/kv { :& [ a b ] :c "something" }
obviously :&
could be anything that is unlikely to be a key.
Funny you should mention this, I was just wondering about this earlier todaythis whole tagged literal thing will not work. basically it will be calling a function with with vector with 4 values (not 4 symbols). it will not be the original form. in CLJS for some reason it is the form so it'll work there but not so in CLJ
this works in clojure but idk if it's a good idea lol:
(defn kw-reader [values]
(loop [[cur-val & next-vals] values
results []]
(cond
cur-val
(recur
next-vals
(if (symbol? cur-val)
(-> results
(conj (keyword cur-val))
(conj cur-val))
(conj results cur-val)))
:else
(->> results
(partition 2 2 nil)
(map vec)
(into {})))))
(binding [*data-readers* {'nb/kw user/kw-reader}]
(let [a :aaaa b :bbbbb d :ddddddd]
#nb/kw [a b :c 1 d]))
;=> {:a :aaaa, :b :bbbbb, :c 1, :d :ddddddd}
What if you want the value of a
to be the key for b
's value? I think you'd need to complicate the syntax to resolve that ambiguity.
But ultimately, even if you fix that, I don't think it is going to take off (even inside a single codebase) - it just won't be concise/convenient enough, there won't be editor support, etc. While in JS, basically everyone will be using that object syntax.
oh yeah, this isn't good lol, just a proof of concept. poking at it, this gets significantly hairier if you want that
Hey guys, I am trying to write pretty fast to a clojure channel, by using the blocking syntax (>!!) Interrupted exceptions keep happening, have you guys gone through something like that?
:cause nil
:via
[{:type java.lang.InterruptedException
:message nil
:at [java.util.concurrent.locks.AbstractQueuedSynchronizer doAcquireSharedInterruptibly AbstractQueuedSynchronizer.java 1040]}]
:trace
[[java.util.concurrent.locks.AbstractQueuedSynchronizer doAcquireSharedInterruptibly AbstractQueuedSynchronizer.java 1040]
[java.util.concurrent.locks.AbstractQueuedSynchronizer acquireSharedInterruptibly AbstractQueuedSynchronizer.java 1345]
[java.util.concurrent.CountDownLatch await CountDownLatch.java 232]
[clojure.core$promise$reify__8486 deref core.clj 7109]
[clojure.core$deref invokeStatic core.clj 2320]
[clojure.core$deref invoke core.clj 2306]
[clojure.core.async$fn__5995 invokeStatic async.clj 175]
[clojure.core.async$fn__5995 invoke async.clj 164]
(defn binary-search [nums target]
(loop [left 0
right (dec (count nums))]
(when (<= left right)
(let [m (quot (+ left right) 2)
actual (get nums m)]
(cond
(= actual target) m
(< actual target) (recur (inc m) right)
:else (recur left (dec m)))))))
(binary-search (range 10) 4)
1. Unhandled java.lang.NullPointerException
Cannot invoke "Object.getClass()" because "x" is null
Now, I can get it to go away by doing
(binary-search (into [] (range 10)) 4)
but i’m curious about the error messageget on range will always give you nil
user=> (get (range 10) 1)
nil
I was just about to mention before you mentioned the vector case that get
was the red flag here
I think nth
just fixes it, and for weird cases gives you a much more intelligible error
of course using nth kind of makes using binary search as an algo silly
probably best to fail if input isn't a vector or array
well, java.util.Collection has binarySearch in it, so writing one in the first place is suspect, but yes 😄
i was just puzzled because i don’t think i’ve ever seen Cannot invoke "Object.getClass()" because "x" is null
before
1. Unhandled java.lang.NullPointerException Cannot invoke “Object.getClass()” because “x” is null Numbers.java: 1095 clojure.lang.Numbers/ops Numbers.java: 253 clojure.lang.Numbers/lt REPL: 119 getclojure.extract/binary-search REPL: 111 getclojure.extract/binary-search REPL: 123 getclojure.extract/eval10259 REPL: 123 getclojure.extract/eval10259 Compiler.java: 7194 clojure.lang.Compiler/eval Compiler.java: 7149 clojure.lang.Compiler/eval core.clj: 3215 clojure.core/eval core.clj: 3211 clojure.core/eval interruptible_eval.clj: 87 nrepl.middleware.interruptible-eval/evaluate/fn/fn AFn.java: 152 clojure.lang.AFn/applyToHelper AFn.java: 144 clojure.lang.AFn/applyTo core.clj: 667 clojure.core/apply core.clj: 1990 clojure.core/with-bindings* core.clj: 1990 clojure.core/with-bindings* RestFn.java: 425 clojure.lang.RestFn/invoke interruptible_eval.clj: 87 nrepl.middleware.interruptible-eval/evaluate/fn main.clj: 437 clojure.main/repl/read-eval-print/fn main.clj: 437 clojure.main/repl/read-eval-print main.clj: 458 clojure.main/repl/fn main.clj: 458 clojure.main/repl main.clj: 368 clojure.main/repl RestFn.java: 1523 clojure.lang.RestFn/invoke interruptible_eval.clj: 84 nrepl.middleware.interruptible-eval/evaluate interruptible_eval.clj: 56 nrepl.middleware.interruptible-eval/evaluate interruptible_eval.clj: 152 nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn AFn.java: 22 clojure.lang.AFn/run session.clj: 218 nrepl.middleware.session/session-exec/main-loop/fn session.clj: 217 nrepl.middleware.session/session-exec/main-loop AFn.java: 22 clojure.lang.AFn/run Thread.java: 833 java.lang.Thread/run
huh. weird. can recreate with just (< 3 nil)
funny there’s no nil check before getting the class for the number operations
I wonder if that’s worth an http://ask.clojure.org question