Fork me on GitHub

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

👍 3

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 :media/title)

(:media/title { "Blah"}) 


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


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?


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


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.: 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.

✔️ 3

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.


subtraction doesn't have an identity element like addition

☝️ 12
👍 3

#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.


+ 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 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...


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


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

💯 3