User Tools


Differences

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

Link to this comparison view

cl:functions:every [2019/06/15 02:00]
cl:functions:every [2019/08/17 15:00] (current)
Line 1: Line 1:
 +====== Function EVERY, SOME, NOTEVERY, NOTANY ======
 +
 +====Syntax====
 +  * **every ** //predicate ''&​rest''​ sequences''​+''//​ → //​generalized-boolean// ​
 +  * **some ** //predicate ''&​rest''​ sequences''​+''//​ → //​result// ​
 +  * **notevery** //predicate ''&​rest''​ sequences''​+''//​ → //​generalized-boolean// ​
 +  * **notany ** //predicate ''&​rest''​ sequences''​+''//​ → //​generalized-boolean//​
 +
 +====Arguments and Values====
 +  * //​predicate//​ - a //​[[CL:​Glossary:​designator]]//​ for a //​[[CL:​Glossary:​function]]//​ of as many //​[[CL:​Glossary:​arguments]]//​ as there are //​sequences//​.
 +  * //​sequence//​ - a //​[[CL:​Glossary:​sequence]]//​.
 +  * //result// - an //​[[CL:​Glossary:​object]]//​.
 +  * //​generalized-boolean//​ - a //​[[CL:​Glossary:​generalized boolean]]//​.
 +
 +====Description====
 +**every**, **some**, **notevery**,​ and **notany** test //​[[CL:​Glossary:​element|elements]]//​ of //​sequences//​ for satisfaction of a given //​predicate//​.
 +
 +The first argument to //​predicate//​ is an //​[[CL:​Glossary:​element]]//​ of the first //​sequence//;​ each succeeding argument is an //​[[CL:​Glossary:​element]]//​ of a succeeding //​sequence//​.
 +
 +//​predicate//​ is first applied to the elements with index ''​0''​ in each of the //​sequences//,​ and possibly then to the elements with index ''​1'',​ and so on, until a termination criterion is met or the end of the shortest of the //​sequences//​ is reached.
 +
 +**every** returns //​[[CL:​Glossary:​false]]//​ as soon as any invocation of //​predicate//​ returns //​[[CL:​Glossary:​false]]//​. If the end of a //​sequence//​ is reached, **every** returns //​[[CL:​Glossary:​true]]//​. Thus, **every** returns //​[[CL:​Glossary:​true]]//​ if and only if every invocation of //​predicate//​ returns //​[[CL:​Glossary:​true]]//​.
 +
 +**some** returns the first //​[[CL:​Glossary:​non-nil]]//​ value which is returned by an invocation of //​predicate//​. If the end of a //​sequence//​ is reached without any invocation of the //​predicate//​ returning //​[[CL:​Glossary:​true]]//,​ **some** returns //​[[CL:​Glossary:​false]]//​. Thus, **some** returns //​[[CL:​Glossary:​true]]//​ if and only if some invocation of //​predicate//​ returns //​[[CL:​Glossary:​true]]//​.
 +
 +**notany** returns //​[[CL:​Glossary:​false]]//​ as soon as any invocation of //​predicate//​ returns //​[[CL:​Glossary:​true]]//​. If the end of a //​sequence//​ is reached, **notany** returns //​[[CL:​Glossary:​true]]//​. Thus, **notany** returns //​[[CL:​Glossary:​true]]//​ if and only if it is not the case that any invocation of //​predicate//​ returns //​[[CL:​Glossary:​true]]//​.
 +
 +**notevery** returns //​[[CL:​Glossary:​true]]//​ as soon as any invocation of //​predicate//​ returns //​[[CL:​Glossary:​false]]//​. If the end of a //​sequence//​ is reached, **notevery** returns //​[[CL:​Glossary:​false]]//​. Thus, **notevery** returns //​[[CL:​Glossary:​true]]//​ if and only if it is not the case that every invocation of //​predicate//​ returns //​[[CL:​Glossary:​true]]//​.
 +
 +====Examples====
 +<​blockquote>​
 +(every #'​[[CL:​Functions:​characterp]] "​abc"​) <​r>//​[[CL:​Glossary:​true]]//</​r>​
 +(some #'​[[CL:​Functions:​math-equal|=]] '(1 2 3 4 5) '(5 4 3 2 1)) <​r>//​[[CL:​Glossary:​true]]//</​r>​
 +(notevery #'​[[CL:​Functions:​math-less|<​]] '(1 2 3 4) '(5 6 7 8) '(9 10 11 12)) <​r>//​[[CL:​Glossary:​false]]//</​r>​
 +(notany #'​[[CL:​Functions:​math-greater|>​]] '(1 2 3 4) '(5 6 7 8) '(9 10 11 12)) <​r>//​[[CL:​Glossary:​true]]//</​r>​
 +</​blockquote>​
 +
 +====Affected By====
 +None.
 +
 +====Exceptional Situations====
 +Should signal **[[CL:​Types:​type-error]]** if its first argument is neither a //​[[CL:​Glossary:​symbol]]//​ nor a //​[[CL:​Glossary:​function]]//​ or if any subsequent argument is not a //​[[CL:​Glossary:​proper sequence]]//​.
 +
 +Other exceptional situations are possible, depending on the nature of the //​predicate//​.
 +
 +====See Also====
 +  * **[[CL:​Macros:​and|Macro AND]]**
 +  * **[[CL:​Macros:​or|Macro OR]]**,
 +
 +{\secref\TraversalRules}
 +
 +====Notes====
 +<​blockquote>​
 +(notany //​predicate//​ //​sequence''​*''//​) ≡ (not (some //​predicate//​ //​sequence''​*''//​))
 +(notevery //​predicate//​ //​sequence''​*''//​) ≡ (not (every //​predicate//​ //​sequence''​*''//​))
 +</​blockquote>​
 +
 +\issue{MAPPING-DESTRUCTIVE-INTERACTION:​EXPLICITLY-VAGUE}