Why Clojure idiom prefer to return nil instead of empty list like Scheme?

前端 未结 4 589
粉色の甜心
粉色の甜心 2021-01-01 21:27

From a comment on another question, someone is saying that Clojure idiom prefers to return nil rather than an empty list like in Scheme. Why is that?

Like,



        
4条回答
  •  清酒与你
    2021-01-01 21:36

    Also note that the union of collection types and nil form a monoid, with concatenation the monoid plus and nil the monoid zero. So nil keeps the empty list semantics under concatenation while also representing a false or "missing" value.

    Python is another language where common monoid identities represent false values: 0, empty list, empty tuple.

提交回复
热议问题