diff lisp/cl-extra.el @ 5226:7789ae555c45

Add Common Lisp's #'complement to cl-extra.el. 2010-06-02 Aidan Kehoe <kehoea@parhasard.net> * cl-macs.el (complement): * cl-extra.el (complement): Add an implementation and a compiler macro for #'complement, as specified by CL. For discussion; the compiler macro may be a little too aggressive about taking the compile time argument lists of the functions it is inverting.
author Aidan Kehoe <kehoea@parhasard.net>
date Wed, 02 Jun 2010 16:18:50 +0100
parents 2d0937dc83cf
children f3eca926258e
line wrap: on
line diff
--- a/lisp/cl-extra.el	Wed Jun 02 15:31:15 2010 +0100
+++ b/lisp/cl-extra.el	Wed Jun 02 16:18:50 2010 +0100
@@ -100,6 +100,14 @@
 ;; XEmacs; #'map, #'mapc, #'mapl, #'maplist, #'mapcon, #'some and #'every
 ;; are now in C, together with #'map-into, which was never in this file.
 
+;; The compiler macro for this in cl-macs.el means if #'complement is handed
+;; a constant expression, byte-compiled code will see a byte-compiled
+;; function.
+(defun complement (function &optional documentation)
+  "Return a function which gives the logical inverse of what FUNCTION would."
+  `(lambda (&rest arguments) ,@(if documentation (list documentation))
+     (not (apply ',function arguments))))
+
 (defun notany (cl-pred cl-seq &rest cl-rest)
   "Return true if PREDICATE is false of every element of SEQ or SEQs."
   (not (apply 'some cl-pred cl-seq cl-rest)))