User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cl:functions:complement [2019/07/14 17:00]
cl:functions:complement [2019/07/17 21:00] (current)
Line 1: Line 1:
 +====== Function COMPLEMENT ======
 +
 +====Syntax====
 +  * **complement** //​function//​ → //​complement-function//​
 +
 +====Arguments and Values====
 +  * //​function//​ - a //​[[CL:​Glossary:​function]]//​.
 +  * //​complement-function//​ - a //​[[CL:​Glossary:​function]]//​.
 +
 +====Description====
 +Returns a //​[[CL:​Glossary:​function]]//​ that takes the same //​[[CL:​Glossary:​argument|arguments]]//​ as //​function//,​ and has the same side-effect behavior as //​function//,​ but returns only a single value: a //​[[CL:​Glossary:​generalized boolean]]// with the opposite truth value of that which would be returned as the //​[[CL:​Glossary:​primary value]]// of //​function//​. That is, when the //​function//​ would have returned //​[[CL:​Glossary:​true]]//​ as its //​[[CL:​Glossary:​primary value]]// the //​complement-function//​ returns //​[[CL:​Glossary:​false]]//,​ and when the //​function//​ would have returned //​[[CL:​Glossary:​false]]//​ as its //​[[CL:​Glossary:​primary value]]// the //​complement-function//​ returns //​[[CL:​Glossary:​true]]//​.
 +
 +====Examples====
 +<​blockquote>​
 +([[CL:​Functions:​funcall]] (complement #'​[[CL:​Functions:​zerop]]) 1) → //​[[CL:​Glossary:​true]]//​
 +([[CL:​Functions:​funcall]] (complement #'​[[CL:​Functions:​characterp]]) #\\A) → //​[[CL:​Glossary:​false]]//​
 +([[CL:​Functions:​funcall]] (complement #'​[[CL:​Functions:​member]]) 'a '(a b c)) → //​[[CL:​Glossary:​false]]//​
 +([[CL:​Functions:​funcall]] (complement #'​[[CL:​Functions:​member]]) 'd '(a b c)) → //​[[CL:​Glossary:​true]]//​
 +</​blockquote>​
 +
 +====Side Effects====
 +None.
 +
 +====Affected By====
 +None.
 +
 +====Exceptional Situations====
 +None.
 +
 +====See Also====
 +  * **[[CL:​Functions:​not|Function NOT]]**
 +
 +====Notes====
 +<​blockquote>​
 +(complement //x//) ≡ #'​([[CL:​Symbols:​lambda]] (&rest arguments) ([[CL:​Functions:​not]] ([[CL:​Functions:​apply]] //x// arguments)))
 +</​blockquote>​
 +
 +In Common Lisp, functions with names like ''//​xxx//​-if-not''​ are related to functions with names like ''//​xxx//​-if''​ in that
 +
 +<​blockquote>​
 +(//​xxx//​-if-not //f// . arguments) ≡ (//xxx//-if (complement //f//) . arguments)
 +</​blockquote>​
 +
 +For example,
 +
 +<​blockquote>​
 +([[CL:​Functions:​find-if-not]] #'​[[CL:​Functions:​zerop]] '(0 0 3))
 +  ≡ ([[CL:​Functions:​find-if]] (complement #'​[[CL:​Functions:​zerop]]) '(0 0 3)) <​r>​3</​r>​
 +</​blockquote>​
 +
 +Note that since the ''//​xxx//​-if-not''​ //​[[CL:​Glossary:​function|functions]]//​ and the **'':​test-not''​** arguments have been deprecated, uses of ''//​xxx//​-if''​ //​[[CL:​Glossary:​function|functions]]//​ or **'':​test''​** arguments with **[[CL:​Functions:​complement]]** are preferred.
 +
 +\issue{FUNCTION-COMPOSITION:​JAN89-X3J13}