This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-11
Channels
- # aleph (38)
- # announcements (6)
- # aws (1)
- # beginners (47)
- # calva (21)
- # cider (47)
- # cljs-dev (18)
- # clojure (40)
- # clojure-europe (7)
- # clojure-india (2)
- # clojure-italy (9)
- # clojure-nl (11)
- # clojure-norway (2)
- # clojure-sanfrancisco (1)
- # clojure-spec (17)
- # clojure-sweden (2)
- # clojure-uk (73)
- # clojurescript (10)
- # cursive (6)
- # datascript (12)
- # datavis (2)
- # defnpodcast (1)
- # duct (5)
- # emacs (36)
- # figwheel (2)
- # figwheel-main (10)
- # juxt (12)
- # leiningen (1)
- # midje (1)
- # nrepl (9)
- # off-topic (25)
- # pedestal (3)
- # portkey (3)
- # quil (2)
- # re-frame (45)
- # reagent (1)
- # ring (3)
- # ring-swagger (36)
- # rum (1)
- # shadow-cljs (48)
- # spacemacs (1)
- # speculative (50)
- # testing (2)
- # tools-deps (27)
- # yada (4)
today the contract for sequence functions is seqable? to seqable?, whether map
returns ()
or nil
is not something you should be thinking about
(if (map a-fn coll) (do-something) (do-else))
That is correct, it is part of a contract though? - yeah minus nil
that’s the question. also: should we consider different return specs for different seq functions, or treat them under the same contract
@mfikes given that ()
or nil
may be treated as the same value (punning), the question is: is this important enough to spec differently
@mfikes start reading here: https://clojurians.slack.com/archives/CDJGJ3QVA/p1547221885081900
map, remove, filter can't return nil - I think it is a bug to write code that relies on them returning nil. If that changes in the future, so will your execution
you are turning things around: you should not rely on them to return ()
instead of nil
, that should be un-important
there are no such things as empty seqs
I think
isn't that an emptylist?
anyhow, I am attacking this mostly from ide tooling angle. I would like to be able to mark code doing (if) on the return of a map as incorrect
Another example where this is relevant:
(re-seq #"\w+" "")
According to the docs it should return a lazy seq. It returns nil
. This should not be regarded as important, since nil
and ()
can be used interchangeably.Yes, but what if that changes in the next version of Clojure, so that nil isn't possible anymore? Nil punning on that stops working. That should probably have an effect on the spec then
You are again turning it around. You should never nil pun on a result of a sequence function…
Yes, and we can have tools that helps with enforcing that
Sure, but those tools should be able to leverage seqable?
and nothing more than that
is (when (re-seq ...)) a bug?
interesting, got any example for re-seq returning an empty-seq instead of a nil?
you’re not supposed to look at the implementation and then figure out that it’s never going to
@andreas862 as @alexmiller pointed out, you should always call seq
on a sequence if used as a truthy value
Sure, but that is why my tooling should mark the bare if-statement
Another example where you shouldn’t rely on seq?
“Returns a sequence of values”
(vals nil) ;;=> nil
(vals {}) ;;=> nil
Same for keys
.My argument has always been about the ones that I classified as not nil-punnable. map, filter, remove etc. I did know about some others returning nil
But have to say that I do probably use some nil return directly
have a lot of code to fix
probably re-seq, not sure about the rest
not that sure about re-seq, have to check. But there is a big risk that I would use one of them if I found that it seemed to leave nil for empty.
We already discussed this in the very start of speculative: https://github.com/borkdude/speculative/issues/45
That’s why we made it seqable?
in the first place. Sorry I forgot about this @andreas862. Should have remembered when I merged the change.
a non-nil seqable isn't invalidated by that issue.
seq? goes out the door though