Please sign in to comment.
IFs with no else clause or a NIL else clause should always be replaced with a WHEN. Here we shadow the standard IF with our own that warns when we violate these style rules. > (defun foo (a) (if (eq a :foo) :baz)) ; in: DEFUN FOO ; (ACADEMY::IF (EQ ACADEMY::A :FOO) :BAZ) ; ; caught WARNING: ; A single legged IF should be replaced with a WHEN. ; ; compilation unit finished ; caught 1 WARNING condition FOO > (foo :foo) :BAZ > (foo 123) NIL > (if :foo :baz nil) WARNING: An if's else of NIL should be replaced with a WHEN. This commit demonstrates * Shadowing core CL functionality with our own cooked up versions. * Using the optional SUPPLIED-P-PARAMETER to distinguish between a supplied NIL and no argument.
- Loading branch information...
Showing with 9 additions and 0 deletions.
|@@ -0,0 +1,7 @@|
|+(defmacro if (test then &optional (else nil else-defined))|
|+ (unless else-defined (warn "A single legged IF should be replaced with a WHEN."))|
|+ (when (and else-defined (null else))|
|+ (warn "An if's else of NIL should be replaced with a WHEN."))|
|+ `(cl:if ,test ,then ,else))|