This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-27
Channels
- # aleph (5)
- # announcements (18)
- # beginners (200)
- # cider (25)
- # cljdoc (4)
- # cljsrn (3)
- # clojure (90)
- # clojure-europe (3)
- # clojure-finland (5)
- # clojure-france (1)
- # clojure-houston (1)
- # clojure-italy (8)
- # clojure-nl (15)
- # clojure-spec (24)
- # clojure-uk (20)
- # clojurescript (199)
- # core-async (2)
- # cursive (45)
- # data-science (14)
- # datomic (33)
- # duct (13)
- # fulcro (4)
- # graphql (3)
- # kaocha (9)
- # leiningen (24)
- # nrepl (16)
- # off-topic (105)
- # pathom (15)
- # pedestal (28)
- # re-frame (1)
- # reagent (14)
- # shadow-cljs (28)
- # spacemacs (8)
- # tools-deps (8)
- # vim (4)
I'm tearing my hair out trying to figure out why com.stuartsierra.component
isn't shutting down one of my components. I have other components that shut down just fine. I can't spot any material difference in this one. I'm about to start trying to expose some details from within component itself but thought I would ask here if there are any common tripping hazards I might not be thinking of
you need to return a valid component map from both startup and teardown of each component
that's the most common reason that teardowns get short-circuited
yeah that looks fine. everything starts up properly and inspecting the component in the system it's all well and good
i've got a log statement (and heck, a println, to rule out a logging issue) on the first line of the (stop)
function and that never gets called
a common thing that does that is dissoc'ing a field a record is defined as having, but here are other things that do it too
user=> (defrecord Foo [a])
user.Foo
user=> (assoc (->Foo {}) :a 1 :b 2)
#user.Foo{:a 1, :b 2}
user=> (dissoc (assoc (->Foo {}) :a 1 :b 2) :b)
#user.Foo{:a 1}
user=> (dissoc (assoc (->Foo {}) :a 1 :b 2) :a)
{:b 2}
user=>
Why does group-by
return a map of vectors instead of respecting the original collection type?
it's easy enough to roll my own version which does that:
(defn group-by*
"Like `group-by` but preserves the original collection type"
[f coll]
(let [emp (empty coll)]
(persistent!
(reduce
(fn [ret x]
(let [k (f x)]
(assoc! ret k (conj (get ret k emp) x))))
(transient {}) coll))))
Is there a way to control the name of a reify
class? I like to have that for profiling to be able to see which implementation I have in the profiler.
By the way: Using ZGC in Java 12 was not suchessful for my compiled code. I still had 5 sec pauses. So I droped the idea to evaluate code during runtime. Now I just use good old protocol dispatch for my expressions. The protocol dispatch is so fast that it’s not slower than directly compiled code.
what do you prefer for the name of a http://micrometer.io wrapper: clj-micrometer or micrometer-clj?
reify needs to gen a unique classes every time so you wouldn't want to force a particular name
protocol dispatch is designed for speed, for sure
you could just use a deftype?
yes I could. I also could use defrecord. But for me the code is more readable using reify.
it’s ok. I’m not totally lost in the profiler. I only liked to ask if I was missing something. But thanks.
https://medium.com/dartlang/making-dart-a-better-language-for-ui-f1ccaf9f546c is there a way to do something like this in clojure? tldr: interpolate values into a list like so:
[:item-1
(add-when condition?
:optional-item-1
:optional-item-2)
:item-2]
assuming its impossible as macros can't expand to multiple expressions as far as I know?
you can do stuff with macros and splicing but its unidiomatic imo
okokok
^ like this guy 😛
(cond-> [:item-1]
condition?
(conj :optional-item-1 :optional-item-2)
:always
(conj :item-2))
I still don’t understand why clojure.datafy.nav
needs both k
and v
see this @stathissideris https://github.com/stuarthalloway/reflector/blob/master/src/com/stuarthalloway/reflector.clj
@ghadi thanks!
java-time/interval
is in the doc but somehow it looks like it can’t be found (I’m on clojure 1.10)
java-time/minus
can be found without problem
@jsabeaudry781 surely this would be a question of your java-time version, and not your clojure version?
is that clojure.java-time
-the-library?
In that case, you will need to add https://www.threeten.org/threeten-extra/ before you get interval’s
(they didn’t make it into java.time.*
but were included in an “extra” library made available by the original proposers of the java.time rework)
Thanks for that! Somehow I missed it in the doc
cheers!
Yeah, I missed it the first few times too
Also, I like that clojure.java-time is correct and such, but it doesn’t feel very idiomatic to use from clojure. I looked at juxt/tick, but thats just not complete and/or mature…
are there other libraries I should be looking at? That are both correct and have nice clojure APIs?
what's the twist @U09LZR36F?
(btw, not trying to offend, tick just doesn’t feel “done” to me just yet)
@UDF11HLKC we're using it in production with several clients, but you're right that there's still some gaps.
Right, I like its way of doing things tho, feels less like a direct wrapper around a java api. Thats why I was asking, I was hoping that I completely missed something as elaborate as clojure.java-time, but with a more clojure-esque API
And thats in the little things right, for example, clojure.java-time does a lot of “java-style” overloading
@UDF11HLKC are there any particular gaps that are a problem for you?
It’s been a while, can’t come up with specifics sadly
If you check it out again, please feel free to open issues for anything you're missing.
Will do!
I'm generating the following code using reflection on a javaclass to generate a reify that will implement all methods on the class. The end result looks like this: https://gist.github.com/jjttjj/95ff42fedd49893d51a4333da3abe436 The type hints on return values and arguments are needed to avoid ambiguity. Currently I'm generating the code as a quoted list of symbols, spitting it to a source file, and reading it. Is there a better way to do this? Is it possible to generate an elaborate reify like this with a macro?
most macros return a list of symbols (the quoting is done so they remain symbols)
the gotcha is that for metadata like type hints you can't just use the metadata reader macro, you need to return a call to with-meta
so instead of ^void foo
you'd have (with-meta foo {:tag void})
ok so
(^void currentTime [this ^long time]
(cb {:time time, :type :currentTime}))
would become
((with-meta current-time {'void true}
[this (with-meta {'long true} time)]
(cb {:time time, :type :currentTime}))
and that should work fine?I edited the metadata after checking in my repl
the with-meta call should only wrap the symbol, and the macro quoting would mean it needs to look different from that
but that's the basic idea - you need to return a list that has the right metadata on the symbols in it
I think people have forgotten or don't know, but, Insomnia, the REST client ( https://insomnia.rest/) has been supporting EDN without any add-on since some months ago
just thought it was worth a mention. I know about this because I added the feature 😛