User Tools

====== Macro COND ====== ====Syntax==== * **cond** //clause''*''// → //result''*''// <blockquote> //clause// ::= //(test-form form''*'')// </blockquote> ====Arguments and Values==== * //test-form// - a //[[CL:Glossary:form]]//. * //forms// - an //[[CL:Glossary:implicit progn]]//. * //results// - the //[[CL:Glossary:value|values]]// of the //forms// in the first //clause// whose //test-form// //[[CL:Glossary:yield|yields]]// //[[CL:Glossary:true]]//, or the //[[CL:Glossary:primary value]]// of the //test-form// if there are no //forms// in that //clause//, or else **[[CL:Constant Variables:nil]]** if no //test-form// //[[CL:Glossary:yield|yields]]// //[[CL:Glossary:true]]//. ====Description==== **cond** allows the execution of //forms// to be dependent on //test-form//. //test-forms// are evaluated one at a time in the order in which they are given in the argument list until a //test-form// is found that evaluates to //[[CL:Glossary:true]]//. If there are no //[[CL:Glossary:form|forms]]// in that clause, the //[[CL:Glossary:primary value]]// of the //test-form// is returned by the **cond** //[[CL:Glossary:form]]//. Otherwise, the //forms// associated with this //test-form// are evaluated in order, left to right, as an //[[CL:Glossary:implicit progn]]//, and the //[[CL:Glossary:value|values]]// returned by the last //form// are returned by the **cond** //[[CL:Glossary:form]]//. Once one //test-form// has //[[CL:Glossary:yield|yielded]]// //[[CL:Glossary:true]]//, no additional //test-forms// are //[[CL:Glossary:evaluate|evaluated]]//. If no //test-form// //[[CL:Glossary:yield|yields]]// //[[CL:Glossary:true]]//, **[[CL:Constant Variables:nil]]** is returned. ====Examples==== <blockquote> ([[CL:Macros:defvar]] *a*) <r>*A*</r> ([[CL:Macros:defun]] select-options () (cond (([[CL:Functions:math-equal|=]] *a* 1) ([[CL:Macros:setf]] *a* 2)) (([[CL:Functions:math-equal|=]] *a* 2) ([[CL:Macros:setf]] *a* 3)) ((and ([[CL:Functions:math-equal|=]] *a* 3) ([[CL:Functions:floor]] *a* 2))) ([[CL:Constant Variables:t]] ([[CL:Functions:floor]] *a* 3)))) <r>SELECT-OPTIONS</r> ([[CL:Macros:setf]] *a* 1) <r>1 </r> (select-options) <r>2 </r> *a* <r>2 </r> (select-options) <r>3</r> *a* <r>3</r> (select-options) <r>1</r> ([[CL:Macros:setf]] *a* 5) <r>5</r> (select-options) <r>1 2</r> </blockquote> ====Side Effects==== None. ====Affected By==== None. ====Exceptional Situations==== None. ====See Also==== * **[[CL:Special Operators:if|Special Operator IF]]** * **[[CL:Macros:case|Macro CASE]]**. ====Notes==== None.