-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specs for clojure.set #70
Comments
PR for speculative.set would make sense to reflect the ns structure in
Clojure. There’s a style guide in doc you can take a look at. Nil: depends
if the set functions are designed to deal with those.
On Thu, 1 Nov 2018 at 13:06, Eero Helenius ***@***.***> wrote:
A while back I wrote specs for the functions in clojure.set
<https://github.com/eerohele/flowthing.set.specs.alpha> after being bit
by (set/union #{:a} [:b :c]).
Would you be interested in merging that code into this project? If so, I
can create a pull request if you want. If you'd rather not, I totally
understand.
I think the specs are in pretty good shape otherwise, except that I
haven't been able to decide whether set functions should allow nil args or
not. While they behave pretty well when given nil args, I have that part is
more or less undefined.
The specs currently allow nil args, but I'm willing to disallow them if
you think that'd be better.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#70>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARZBqqySONNUC7TEH25_cRUOXKm46_qks5uquOugaJpZM4YGR7x>
.
|
@eerohele Because we'd like to have this repo in a state that lets the whole or part of it be included into clojure.core, we need the contributors to have signed the Clojure CA. |
Snippet from chat in #clojure-spec on Slack. borkdude [4:22 PM] In other words should a spec for those functions account for nil input or throw |
@eerohele Given the above, I think treating input and output as nilable sets makes sense. |
Note: In the |
Here is a Clojure JIRA ticket with a patch that proposes specs for clojure.set/union and a couple of other clojure.set functions, but those proposed specs may be not what is desired by the Clojure core team. https://dev.clojure.org/jira/browse/CLJ-2287 |
@jafingerhut I think that usage of union is similar or equal to the usage of
So the question remains, why did Stu not did that... maybe he forgot a call to |
I agree that question remains. Sorry, I don't have the answer. |
When I researched the behavior of clojure.set functions when passed non-set args a while back, I stumbled upon this comment by Alex Miller:
In light of that comment, it seems to me that doing something like However, I'm inclined to agree that there's bound to be a somewhat significant amount of code that relies on set functions being able to accept nil args and that it might be better to allow them. Here's another consideration regarding clojure.set: if you clone the Day of Datomic repo, enable instrumentation with the specs I wrote and evaluate the namespace, you get this error (with Expound): https://gist.github.com/eerohele/7689259057ed976aba26e4fd1a83792c In other words, somewhere in Datomic's code base there's a call to |
My thoughts:
|
Sounds reasonable to me.
I could look into it, but I don't currently know how to do that. It might be possible to create a custom spec error printer that prints the type, but I'm not sure. |
You can write a different predicate than |
That's a good point. I'll do it when I get the chance. |
It's a I didn't know (set/map-invert (java.util.HashMap. {:foo :bar}))
;=> {:bar :foo} So maybe we could do something like this? (defn hash-map?
[x]
(instance? java.util.HashMap x))
(spec/def ::map-like (some-fn map? hash-map?)) Then use |
Given that
explains why So a special case for This also works:
|
@eerohele One more thought. I think we can assume for now that a reducible collection of I just pushed a spec for Here is the spec for a reducible coll: You can combine those two to spec the input for |
How far down Hyrum's law do people want to go here? I'm guessing "any instances of Java objects that can be passed to function X as arguments, that returns a Java object that satisfies the properties of an object that we think X ought to return" could get pretty convoluted, and must in general be computationally undecidable. |
@jafingerhut Can you be more specific? Is a reducible of map-entry too Hyrum for you? |
When Clojure 1.9 came out, some ns forms that were permitted before became illegal, because of specs. Not many, but a few. It seems plausible to ask whether some of the calls in Datomic and/or clojure.data/diff should similarly become spec errors for functions in clojure.set. Sure, given their authors, one should question carefully whether they become errors or are allowed, but it seems worth asking. |
@jafingerhut Posted some questions in #46. For map-invert a
|
Some additional findings regarding
|
|
merged |
Using generative testing I found some cases where
so in general |
A while back I wrote specs for the functions in clojure.set after being bit by
(set/union #{:a} [:b :c])
.Would you be interested in merging that code into this project? If so, I can create a pull request if you want. If you'd rather not, I totally understand.
I think the specs are in pretty good shape otherwise, except that I haven't been able to decide whether set functions should allow nil args or not. While they behave pretty well when given nil args, I think that part is more or less undefined.
The specs currently allow nil args, but I'm willing to disallow them if you think that'd be better.
The text was updated successfully, but these errors were encountered: