This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-01
Channels
- # arachne (3)
- # bangalore-clj (8)
- # beginners (9)
- # cljsrn (3)
- # clojure (148)
- # clojure-filipino (2)
- # clojure-russia (25)
- # clojure-serbia (3)
- # clojure-spec (14)
- # clojure-uk (61)
- # clojureremote (7)
- # clojurescript (38)
- # clojurewest (2)
- # cursive (2)
- # data-science (9)
- # datomic (4)
- # emacs (4)
- # jobs (6)
- # lein-figwheel (3)
- # leiningen (2)
- # off-topic (1)
- # om (3)
- # onyx (1)
- # pedestal (16)
- # perun (2)
- # powderkeg (1)
- # protorepl (2)
- # re-frame (1)
- # reagent (10)
- # spacemacs (2)
- # unrepl (5)
- # untangled (4)
maws.core> (if [] (print "Hello"))
Hello
nil
maws.core> (if nil (print "Hello"))
nil
The empty list is not nil and not false? Yet nil can be used in place of an empty seq, list, map. So nil = [] but [] != nil Equality is no longer commutative.
Well for actual clojure equalities it’s always false so at that level it is commutative.
maws.core> (= nil [])
false
maws.core> (= [] nil)
false
maws.core> (:matt nil)
nil
maws.core> (:matt {})
nil
Up to the point I can switch nil in for an empty map. But I can’t swap in an empty map for a condition.
if what you're asking were true what'd follow would be that () = [] = {} = nil
which is clearly nonsensical
@mattford no, nil is not the empty list/vector/map in any context. some functions will coerce nil to either one of those but it doesn't imply equality
it just so happens that get
will return nil if trying to access elements from a non associative data structure
@mattford the distinction you have to understand is that nil
isn't or doesn't behave like an empty collection in some contexts, some functions decide to return the same result when invoked on nil as they do if invoked on an empty collection but that's up to the specific function
e.g. if you have a function that acts on maps and you pass nil, it's likely that (f nil)
will produce the same result as (f {})
altho it's true that almost all functions that operate on seqs, behave on nil
as if they were acting on ()
well to be fair i can't think of any sequence function right now that doesn't operates differently on nil than it does on empty seqs
(in clojure the concept of a sequence is different from the more general concept of a collection)
I started on this road by using cond
and assuming the empty list,seq, map would be false.
Yep - but I noticed that nil (mostly) worked as the empty list and couldn’t understand how that would work. Until you explained.
There’s a table here and some further interesting discussion in the links http://stackoverflow.com/questions/5830571/why-did-father-of-clojure-say-that-schemes-true-false-are-broken
@mattford does it help to consider that (seq [])
, (seq '())
, (seq {})
, and (seq nil)
all produce nil
-- and all sequence functions start by call seq
on their argument to handle an empty sequence. This makes it much easier to compose sequence functions since you don't have to worry about nil
-- it will just pass through safely.
Say I’m collecting the results of a bunch of functions in a vector, they return nil if they don’t do anything. Normally I’d just flatten it.
@mattford You can drive boot from the REPL, don’t think you can with Leiningen.