This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-13
Channels
- # bangalore-clj (1)
- # beginners (29)
- # boot (13)
- # braveandtrue (5)
- # clara (5)
- # cljs-dev (42)
- # cljsrn (7)
- # clojure (55)
- # clojure-france (46)
- # clojure-nl (11)
- # clojure-portugal (1)
- # clojure-russia (268)
- # clojure-spec (26)
- # clojure-uk (32)
- # clojurescript (173)
- # clr (2)
- # core-async (46)
- # cursive (22)
- # datomic (33)
- # devcards (1)
- # emacs (5)
- # events (8)
- # figwheel (2)
- # flambo (4)
- # instaparse (8)
- # jobs (11)
- # klipse (46)
- # lein-figwheel (3)
- # london-clojurians (2)
- # nrepl (1)
- # off-topic (29)
- # om (4)
- # om-next (8)
- # pedestal (3)
- # rdf (4)
- # re-frame (51)
- # reagent (104)
- # remote-jobs (1)
- # rum (4)
- # schema (2)
- # specter (19)
- # untangled (16)
- # vim (52)
wanted to share a dumb moment I had, so others who may run across this can recall it.
I was using a when-let
to pull the first arg from a vector (it was the result of an async alts!!
, fwiw):
(when-let [status (first [200 "blah" "blah"])]
(println "status: " status)) ;; prints status: 200
Of course, when the first element is nil, then the println
is not executed:
(when-let [status (first [nil "blah" "blah"])]
(println "status: " status)) ;; nothing prints, as expected
I thought I'd be clever and destructure the vector:
(when-let [[status] [200 "blah" "blah"]]
(println "status: " status)) ;; works great, prints status: 200
But when the first element is nil, as in the 2nd example, the println
is still executed:
(when-let [[status] [nil "blah" "blah"]]
(println "status: " status)) ;; prints status: nil
Now, in hindsight, it's clear that this works because [nil]
is not nil
, so the when-let
clause is executed. However, it's a bit tricky due to the destructuring. It's a case where you cannot replace (first ...)
with a destructuring. Not rocket science, very obvious, but wasted quite a lot of time on this. It was a bit more difficult to debug due to the vector coming from channels, and thinking that the issue was with my async code, when in face it was with this... Anyway, hope it helps 🙂Just recently started using qualified keywords more and I feel like I'm missing something. What's the idiomatic way of qualifying all the key in m
(`(def m {:foo "a" :bar 0})`)? If I construct the map directly I can do #:command{:foo "a" :bar 0})
straight away, but if it comes as a variable I can't find a clean solution. Is it just a syntax thing or have I missed a stdlib function?
Right now I'm hacking around it by doing this horrendous thing:
(->> m
(map (fn [[k v]] [(keyword "command" (name k)) v]))
(into {}))
@joshjones The ability to put nil / null into java collections has been a constant soure of pleasure and surprises in Java since it exists 😄
Wouldn’t it make more sense to use java’s native format in the api? Currently, we do a lot of conversion back and forth to mitigate this
everyone does
I think
the reason probably is for performance: you only have to convert to and from java.util.Date once
if you have a series of transformations, like now
, 2 days before
, at midnight
, ...
@grav java.util.Date
is really old, java 8 introduced java.time.*
which is somewhat like joda-time
Okay. Well, the reason we use java.util.Date at all is probably
> (type #inst”2017")
java.util.Date
you can also override the #inst
behavior
I'd rather stick with java.util.Date
which is widely used in libraries
That’s what I’m thinking too. I don’t think performance is the issue, more developer experience 🙂
and shuffle back and forth to JodaTime/clj-time when complicated operations are needed
Morning. Published this: https://cb.codes/how-to-read-and-debug-clojure-stack-traces/ to try to help alleviate some of the pain points with error messages
I've been meaning to write something like this to point people at for a while, so thanks for writing this.
One other thing I'd say that's often super useful are lines in the stack traces like:
at clojure.lang.Compiler.load(Compiler.java:6958)
and
at clojure.lang.Compiler.eval(Compiler.java:6511)
Any lines like this indicate that the function was executing at compile time not runtime, so was likely a file loading (indicated by another stackframe) or an error in macro-expansion or at read-time etc. Knowing whether the error occurs at read time, compile time or runtime is usually one of the first things I look for in a stack trace.
Whilst there are definitely a few hard edges in clojure's error messages, if you're experienced at reading them they're really not that bad and can be very informative.
@gfredericks @pesterhazy in 1.9 there is a protocol for insts and it extends to java.time.Instant if it's available on the classpath
Nice!
#inst
literals will still resolve to java.util.Date I assume?
I expect so
Yeah, I believe so
I think I remember someone saying that #inst
would evaluate to java.util.Date
until Java 7 is no longer supported. 😬
Hey, does anyone know where the function lives in Java (or clojure core) that turns clojure symbols into java-ey strings eg: some-class? => SOME_CLASS__QMARK etc
It’s in clojure.lang.Compiler https://github.com/clojure/clojure/blob/b80e1fe4b14654d943e2f8b060b0bc56e18b4757/src/jvm/clojure/lang/Compiler.java#L2889
which is also exposed as clojure.core/munge. you probably want to use that instead of a java call
thanks, @maxfurman !
@tjtolton probably not part of Clojure's API though 🙂 https://clojure.org/reference/java_interop#_calling_clojure_from_java
@val_waeselynck apparently you can just call (munge s) to use that
@tjtolton oh my mistake
yeah exactly
is there a repl channel were you can test commands?
is it a slash command?
nice thank you!
Has anyone here worked with buddy and google's certs to unsign a JWT? https://www.googleapis.com/oauth2/v1/certs https://github.com/funcool/buddy-auth
Little confused by the multiple certificates google offers, if I'm supposed to attempt unsigning with each or in series or if I need to write them individually to files to use
hihi
can I add something (build the "materialized views") to the data in atom when it's updated?
if I use add-watch
, won't it be called twice (actually, repeatedly), if I update the atom in its watch?
yeah, you probably don't want to update an atom from inside that watch's atom
but you can update a different atom and create a dataflow of sorts.
be aware thought that watches are not coordinated so if two threads modify the same atom, the order in which the watches are fired is undefined.
is the cognitect blog down ?
working for me
@tbaldridge thanks. so there's no way I stay with one atom?
@leov sure there is, you just add regen-views
inside your swap! function everytime update the atom
in other words, regen your views inside the swap function instead of outside