Fork me on GitHub
Yogesvara Das08:06:06

I'm using spec. Is there 1. A way to check if a collection contains keywords? 2. A way to make unexpected keys cause the conform check to fail?


You can use arbitrary functions as spec predicates, so "yes" to both.

Alex Miller (Clojure team)11:06:22

On the first one, something like (s/coll-of keyword?)


I have a large number of items for which I need to run a db query and save each result. I'm currently collecting the query results in a for-loop and the consuming the result by saving it to the db as one write transaction. The query for some of the items may throw an exception, which makes my implementation brittle. The queries are also resource-intensive and take a long time. Can anyone suggest some improvements to my implementation?


I feel like I'm going crazy; I'm following the It mentions the find-versions tool, also mentioned by the When I run the example code for finding maven artifact versions, it fails.

$ clj -X:deps find-versions :lib
Unqualified function can't be resolved: find-versions
$ clj -version
Clojure CLI version
What am I doing wrong?


Ok, I think my ~/.clojure/deps.edn might be old...


Indeed... it's working now.

Joshua Suskalo16:06:24

I'm implementing a mutable collection and attempting to have it implement some relevant Clojure interfaces, like Seqable , Sequential, IObj, IHashEq, etc. This collection is mutable because it's intended as an alternative to a java.util.concurrent collection that is missing a critical api that I need in my application of this data structure. I am currently implementing metadata-related interfaces, and while IObj is pretty obvious how to implement, I'm not sure how to implement IMeta, because it's not entirely clear to me what API it's intending to present. Specifically, I know it's intended to return an object that is equal to the old one with new metadata, but because this is a mutable value it should only compare as equal if the two objects are identical? (according to the definition of egal), which implies that it should mutate the meta on the original object, but that feels incorrect to me since it appears as if that's the intended definition of the methods on IReference, which I would like to implement, but I'm unsure if I can if I can't define a sensible IMeta implementation, since IReference extends it. So I guess my question is: is it acceptable for IMeta implementations to mutate the original object, and if not, should I just provide my own functions for changing the metadata even though Clojure already has them with alter-meta!?

Joshua Suskalo16:06:08

Maybe important information here is I'm specifically not implementing the IPersistentCollection interface as this collection is not persistent or immutable.


you should not implement IObj

Joshua Suskalo16:06:55

Oh? That surprises me. What part of the contract for IObj am I not conforming to?


I think you got IObj and IMeta reversed


IMeta is just reading metadata


IObj is adding metadata to an immutable value

Joshua Suskalo16:06:06

Ah, I see, yeah, it looks like I did have them swapped around in my head


vars, atoms, and refs (mutable objects) implement IMeta but not IObj

Joshua Suskalo16:06:40

Thanks, that clears it up.


you can implement IReference like the mutable things do

Joshua Suskalo16:06:33

Yeah, that's what I was thinking of. I just got confused because I had IMeta and IObj swapped in my head but saw IReference extends IMeta

Joshua Suskalo18:06:24

It's occurred to me that perhaps I shouldn't implement IHashEq either as the hash can change over time across multiple calls, since it's mutable. Should I be using the default java hash implementation that's basically just based on object identity and leaving this hash out entirely since this is a mutable collection?

Joshua Suskalo16:06:57

Looks like I just had IMeta and IObj backwards in my head.


I'm trying to better understand this statement: > You can reference your own own custom authorizers. Note that this is running as a named tool, so the deps of your projects are not loaded in the current runtime. You can, however, load namespaces from the root of your project (eg from "."). from I was able to get a custom authorizer working by defining a function in a namespace in a .clj file in the project root (like it says). Is that my only option, or can I modify/initialize the environment in some way so that I can reference a function in a namespace under src/ or some subdirectory?