Since you are not using the else branch, you can use when :
(defun safe-div (ab) (when (and (numberp a) (numberp b) (> b 0)) (/ ab)))
which matches with:
(defun safe-div (ab) (if (and (numberp a) (numberp b) (> b 0)) (/ ab) nil))
which matches your version, but more explicit.
In any case, they are all functionally equivalent. I would rather think about how these features will be used. If you do it this way, you will have to do null checks every time you call these functions, which is tedious.
It is better to use conditions either through type declarations, through statements, or through explicit when & hellip; signal . You can then define handlers and restart these conditions for entire parts of your program. Further reading: Practical General Lisp, chap. 19 .
In this case, I would not cope with this at all:
(defun safe-div (ab) (/ ab))
(or rather, just use / ).
If / receives the wrong arguments, it will signal an error that you can handle externally, where you know what that might mean.
source share