Fork me on GitHub
#clojure
<
2020-09-03
>
lilactown00:09:09

Yes I usually use unqualified keys as the applicability of my operations widens

👍 3
lilactown00:09:01

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)

lilactown00:09:46

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

chucklehead01:09:48

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"}) 

p-himik08:09:59

That would make the "is a" relationship much, much more literal. :)

wombawomba12:09:06

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?

chrisblom12:09:04

you can use reflection to make the private method accessible and call it

wombawomba12:09:01

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.

borkdude12:09:21

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?

wombawomba12:09:35

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?

wombawomba13:09:52

Oh, apparently there’s a getDeclaredConstructor reflection method that can be used to access private constructors. I’ll just use that.

✔️ 3
adamfrey14:09:53

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.

bronsa14:09:38

subtraction doesn't have an identity element like addition

☝️ 12
👍 3
adamfrey14:09:02

#math haha. Thanks

Drew Verlee02:09:35

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.

Drew Verlee02:09:00

I would think they should both have a zero arity.

dpsutton03:09:07

+ has an identity element e such that for all x, e + x = x + e = x. There is no such element e for -.

dpsutton03:09:30

suppose there were an e. then

e - x = x - e = x
we can derive that e = x so no single e can exist

Drew Verlee05:09:28

I see the issue more clearly now, thanks.

Drew Verlee06:09:50

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.

Drew Verlee06:09:25

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.

Drew Verlee06:09:45

I know it's not going to change but it's interesting...

isak19:09:45

Is there something like clojure.lang.ILookup that I can implement for an object to have (get my-object k) work on it?

Joe Lane19:09:27

I think you just answered your own question @isak

isak19:09:05

Ah it does work, my first test was broken. Thanks @joe.lane

💯 3