5 ms·
This is because in Common Lisp, nil is an instance of the null class, the one and only instance. You can specialize method arguments to the null class, so that
by kazinator 3y ago
This is because in Common Lisp, nil is an instance of the null class, the one and only instance. You can specialize method arguments to the null class, so that they capture nil arguments, which is very useful and good. (Mind you, I can't think of anything built into the language which exploits this, let alone for converting nil to 0.0.)
Some things in Ruby are patterned directly after Lisp. You notice it here and there, like the #<...> notation for unreadable objects, or calling small integers fixnum, ...
In the world of static reference OOP like Java and C++, there is the Null Object Pattern:
https://en.wikipedia.org/wiki/Null_object_pattern https://en.wikipedia.org/wiki/Null_object_pattern
Because nil is the empty list, one use for specializing on the null class is for handling the empty case of a list.
(defmethod do-some-list-thing ((list null))
;; empty list case
...)
(defmethod do-some-list-thing ((list cons))
;; non-empty case
...)