Fork me on GitHub
#clojure-spec
<
2018-11-01
>
borkdude15:11:16

Is nil considered valid input for Clojure set functions? 0 arity returns empty set, but 1 arity with nil returns nil

borkdude15:11:44

In other words should a spec for those functions account for nil input or throw

seancorfield15:11:23

@borkdude Could you show some code? I'm not sure what you're asking.

borkdude15:11:32

(set/union) vs (set/union nil), they differ in return type

seancorfield15:11:35

set/union is only defined for arguments that are sets tho', right?

seancorfield15:11:54

(and nil is not a set -- so it's "garbage-in, garbage-out" here?)

seancorfield15:11:02

So I guess the answer to your question is "No, a spec for those functions should not allow nil as input".

borkdude16:11:55

If we can agree for union etc. that 1) :ret should be set? then we must either 2) reject nil inputs in the :args spec, or 3) assert that the implementation is wrong

borkdude16:11:53

maybe @alexmiller can say something on this

borkdude16:11:39

would we find it useful for fdefs detect nil (as an instance of non-sets) inputs for set fns?

borkdude16:11:31

or can we say this is undefined territory and assume the simpler spec

Alex Miller (Clojure team)16:11:36

I think right now I would treat both inputs and output as nilable

Alex Miller (Clojure team)16:11:48

as existing code may be relying on the behavior of those things

borkdude16:11:54

if we don’t allow nil, we will find out 🙂

Alex Miller (Clojure team)16:11:12

if your spec fails on working existing code, I think your spec is wrong

borkdude16:11:32

true, but I mean, we can actually discover if people use this in the wild and then adapt the spec accordingly

Alex Miller (Clojure team)17:11:47

I don’t know how else to say it

Alex Miller (Clojure team)17:11:41

you asked for my opinion. My opinion is that you should spec the inputs and output as nilable.

borkdude17:11:14

yes, I wondered why you disagree with adapting the spec gradually when we discover that people actually use those fns like that

borkdude17:11:33

but maybe we can rightaway assume people do this

Alex Miller (Clojure team)17:11:29

nils are often used interchangeably with empty collections. it seems unlikely to me that there is not some code relying on this either for input or output

borkdude17:11:39

next case…

(clojure.set/union 3)

borkdude17:11:00

the identity function….

borkdude17:11:49

I think it’s safe to assume people do not use the 1-arity as the identity function 😉

Alex Miller (Clojure team)17:11:52

I think you can figure that one out

borkdude17:11:07

thanks for the replies

danielcompton20:11:28

Is there a recommended way of running stest/check in a deftest? I looked around and couldn't see anything official, just lots of different ways people did it

borkdude20:11:58

@danielcompton if there is I’d like to know, because I’m doing that right nw

borkdude20:11:08

@danielcompton I’m trying to write tests for clojure, cljs and self-hosted cljs all within one .cljc file. Guess what, all three environment expect and return different keys for the clojure.test.check opts/rets.

bmaddy20:11:21

@borkdude, @danielcompton There was a short discussion about that yesterday. People suggested using test.chuck (not a typo) or separating your property based tests out and run them separately.

bmaddy20:11:52

This is mainly because I'm curious, but does anyone now why the args passed to :fn in s/fdef are conformed values? I'd like to use the actual value in there, but dealing with the conformed value is tricky.

borkdude20:11:09

@bmaddy does test.chuck support .cljc?

bmaddy20:11:53

I've never used it, but the readme says this in the Acknowledgements section: @nberger for adapting to cljc format for ClojureScript, and general maintenance help

andy.fingerhut20:11:59

@borkdude Fine detail nit on your earlier questions -- in the clojure.data/diff implementation there are calls at least clojure.set/union, and perhaps a couple of other clojure.set functions, with sequences as arguments (the return value of the clojure.core/keys function IIRC), so not a set and not nil. I believe the implementation of clojure.set/union for the ways they are called from clojure.data/diff always return correct results (i.e. duplicates in the return value are only harmful for performance, not correctness of the clojure.data/diff results). Not sure if that is considered a bug or something that an 'official' spec for clojure.set/union should allow. https://dev.clojure.org/jira/browse/CLJ-1087 I am an interested observer of such detailed questions, too, not a policy maker.

andy.fingerhut20:11:39

OK, I've just added a comment to that issue with a copy/paste of what I just said above.

👍 4