mark-naylor-1701

elisp if-not macro

Nov 18th, 2025
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.61 KB | None | 0 0
  1. ;; At times I need a condition that that is opposite. That gives me two options,
  2. ;; * come up with negation test that may not read clearly
  3. ;; * wrap the test in a (not test) form
  4. ;; * do the test, but swap the /then/ and /else/ parts.
  5. ;;
  6. ;; Since I'm a lazy programmer, the first two options don't appeal to me. The third option seems ugly to me. This macro takes the second option, but makes it invisible to the programmer.
  7.  
  8.  
  9. (defmacro if-not (cond then &rest else)
  10.   "Reverses the meaning of the conditional. Saves some typing and lets the code
  11. read better."
  12.   `(if (not ,cond)
  13.        ,then
  14.      ,@else))
  15.  
Advertisement
Add Comment
Please, Sign In to add comment