Null object: Difference between revisions

→‎Beginnings of Null Object: Spelling, grammar, mandatory link to Wikipedia. :)
(→‎{{header|Common Lisp}}: Rewrite. Also, no discussion of unbound variables since the task description explicitly says it's not about this issue.)
(→‎Beginnings of Null Object: Spelling, grammar, mandatory link to Wikipedia. :))
Line 180:
The idea of making functions accept <code>nil</code> without failing did not appear in early Lisps. For instance <code>(car nil)</code> was erroneous: it was incorrect to try to access the first element of a non-list.
 
The defaulting behavior <code>(car nil)</code> which Common Lisp programmers take for granted was introduced in InterLisp, and then copied into MacLisp. (InterLisp had other liberties that do not survive ininto Common Lisp: it was possible to call a function with insufficient arguments, and the missing ones defaulted to <code>nil</code>. Likewise, excess arguments were ignored. CL has a disciplined syntax and semantics for default and varialevariable arguments.)
 
This <code>(car nil) -> nil</code> behavior shows <code>nil</code> in an kind of new role: the role of a null object which takes methods that apply to other objects and provides some default non-failing behavior. It is the beginnings of the "[[http://en.wikipedia.org/wiki/Null_Object_pattern null object design pattern"]].
 
====Object-Oriented Null Object====
Anonymous user