Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> You'll find that while maps are in theory lists of vector pair

They aren't. When you seq over a map you get a list of MapEntry, like so: (clojure.lang.MapEntry. :a 1)

MapEntries aren't vectors, and while they can be destructured like vectors, you can't make empty instances of them.

(empty) still is useful in a variety of cases. See for example this bug report that I've filled: http://dev.clojure.org/jira/browse/CLJ-1476



    user=> (pr-str (seq {:a 1 :b 2}))
    "([:a 1] [:b 2])"
    user=> (vector? (first (seq {:a 1 :b 2})))
    true
It looks like a vector, it quacks like a vector...


    user=> (doc vector?)
    -------------------------
    clojure.core/vector?
    ([x])
      Return true if x implements IPersistentVector
    nil
So `MapEntry` implements `IPersistentVector`, but is not a vector. It does not make sense to have an empty `MapEntry`, so IMHO the behavior implemented is valid.


'Hey, if I peek under the abstraction, it all makes sense'. Obviously. The code does what it's written to do. That doesn't make such leaky abstractions okay. `vector?` is, AFAIK, the way to check if something is a vector, and if empty doesn't work on some `vector?`s, then i can't trust it.

empty mapentry returning nil is meh. If it returned an empty vector it'd be what you want 99% of the time.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: