Null, Nil-Punning and You

Hoare’s null references break typing’s promise in ALGOL (and other statically typed languages). If type T is declared to hold reference to a specific thing, but can hold a non-value (null) satisfying none of T’s operations, the type checker is not actually guaranteeing and dereferenes must be checked manually.

In Lisp, nil isn’t in a static contract (e.g. that a variable is a cons cell); the value is checked on use and nil has defined behavior, although it differs on dialect. Common Lisp conflated () and nil while making (car nil), (cdr nil) and nil evaluate to nil, while Scheme distinguishes ``()and#f`. Conflating false, empty list and no value, like Common Lisp, is called nil punning. Some hate and Clojurists praise it.

In Janet, nil and false are falsey yet distinct; empty? checks collections, not nil?.

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论