This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-03
Channels
- # announcements (11)
- # atom-editor (8)
- # aws (16)
- # babashka (34)
- # beginners (59)
- # calva (32)
- # cider (8)
- # clj-kondo (43)
- # cljs-dev (52)
- # clojure (26)
- # clojure-europe (11)
- # clojure-italy (2)
- # clojure-nl (5)
- # clojure-spec (16)
- # clojure-uk (44)
- # clojurescript (5)
- # core-async (21)
- # cursive (14)
- # datomic (53)
- # figwheel-main (4)
- # fulcro (5)
- # graphql (6)
- # java (3)
- # kaocha (5)
- # leiningen (6)
- # local-first-clojure (1)
- # malli (25)
- # off-topic (40)
- # other-languages (1)
- # pathom (5)
- # pedestal (3)
- # re-frame (4)
- # reitit (2)
- # reveal (8)
- # rum (21)
- # sci (16)
- # shadow-cljs (90)
- # spacemacs (8)
- # tools-deps (10)
- # vrac (6)
- # xtdb (12)
E.g. if I have a function that only operates on YouTube videos, then I’d rather talk about a YouTube video entity specifically (using namespaced keywords)
But if I take any number of kinds of videos, then your un-namespaced version with a “service” key is far better than checking to see if a bunch of namespaced keys are nil or not
might be interesting in those cases if you could used derived keywords for map access, i.e.:
(derive :youtube.video/title :media/title)
(:media/title {:youtube.video/title "Blah"})
I need to call a private constructor on a Java class instead of the provided factory method. What’s the easiest way to do this?
like how it's done here: https://stackoverflow.com/questions/880365/any-way-to-invoke-a-private-method
Yeah I tried that, but AFAICT there’s no way to get getDeclaredMethod
to resolve constructors. Also, while there is getConstructors
method, it can only be used for public constructors.
Does Clojure offer something like dynamic binding for multimethods?
E.g.:
https://gist.github.com/borkdude/e9d333b8e4fae210a36bafdd0bbfa3ab
but then done via binding
on the multimethod + dispatch value?
Another viable option in my case would be to inherit from the class and just replicate what the private constructor does (which is to set a few final
fields). Is this doable?
Oh, apparently there’s a getDeclaredConstructor
reflection method that can be used to access private constructors. I’ll just use that.
I just learned that clojure.core/-
doesn't have a zero-arity like clojure.core/+
does.
Does anyone have know of a JIRA ticket or somewhere else people have discussed this before? It's not easy to google for.
Can you elaborate? I understand the explanation, but why doesnt subtraction have a zero arity? I can't tell if they're is some math quirk at play or if it's just an implantation detail. (- 1) is -1 so we're saying the 0 - 1. So we're supplying zero to the 1 arity version.
I would think they should both have a zero arity.
+ has an identity element e
such that for all x, e + x = x + e = x
. There is no such element e
for -
.
suppose there were an e. then
e - x = x - e = x
we can derive that e = x
so no single e
can existI see the issue more clearly now, thanks.
It's because addition is relative to zero. As where subtraction is relative to the input. I guess a zero tells you the operation couldn't have been a no arg subtraction. But throwing an error always seems wrong to me. Maybe nil instead? Like you gave subtraction nothing and so it's just passing it through.
Or maybe nil because we can think of this as a lookup function for the the identity and we get nil when we lookup something that isn't there.
I know it's not going to change but it's interesting...