2 ms·
Nope. You have choices: (defmethod quack ((foo string)) ... ;; foo is never anything but a string here. ... ;; definitely not nil! ) (defmeth
by kazinator 11y ago
Nope. You have choices:
(defmethod quack ((foo string))
... ;; foo is never anything but a string here.
... ;; definitely not nil!
)
(defmethod quack ((foo null))
... ;; foo is definitely nil here
)
Unlike in languages where you have a String reference that can be null, a CLOS method parameter specialized to a string cannot be NIL!
We can also have this piece of minimalism, quite often recurring in Lisp code:
;; yield x if it is not nil, else yield y
(or x y)
Or play hardball:
;; if calculation signals an error,
;; catch it and keep going
(ignore-errors (calculation x))
After programming in Lisp for a while you would never write:
(if (not (null x)) ...)
because it is verbose way of expressing:
(if x ...)
Every value is its own test for non-nullness, since every value is a generalized boolean which stands for falsehood if it is nil, and truth otherwise.