# Differences

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

 cl:macros:and [2019/07/14 17:00] cl:macros:and [2019/10/19 17:00] (current) Line 1: Line 1: + ====== Macro AND ====== + + ====Syntax==== + * **and** //​form''​*''//​ → //''​result''​*''//​ + + ====Arguments and Values==== + * //form// - a //​[[CL:​Glossary:​form]]//​. + * //results// - the //​[[CL:​Glossary:​value|values]]//​ resulting from the evaluation of the last //form//, or the symbols **[[CL:​Constant Variables:​nil]]** or **[[CL:​Constant Variables:​t]]**. + + ====Description==== + The macro **and** evaluates each //form// one at a time from left to right. As soon as any //form// evaluates to **[[CL:​Constant Variables:​nil]]**,​ **and** returns **[[CL:​Constant Variables:​nil]]** without evaluating the remaining //forms//. If all //forms// but the last evaluate to //​[[CL:​Glossary:​true]]//​ values, **and** returns the results produced by evaluating the last //form//. + + If no //forms// are supplied, ''​(and)''​ returns **[[CL:​Constant Variables:​t]]**. + + **and** passes back multiple values from the last //​[[CL:​Glossary:​subform]]//​ but not from subforms other than the last. + + ====Examples==== + <​blockquote>​ + ([[CL:​Macros:​when]] (and (>= n 0) + ​([[CL:​Functions:​math-less|<​]] n ([[CL:​Functions:​length]] a-simple-vector)) + ​([[CL:​Functions:​eq]] ([[CL:​Functions:​elt]] a-simple-vector n) 'foo)) + ([[CL:​Functions:​princ]] "​Foo!"​)) + ​ + + The above expression prints ''​Foo!''​ if element ''​n''​ of ''​a-simple-vector''​ is the symbol ''​foo'',​ provided also that ''​n''​ is indeed a valid index for ''​a-simple-vector''​. Because **and** guarantees left-to-right testing of its parts, **[[CL:​Functions:​elt]]** is not called if ''​n''​ is out of range. + + <​blockquote>​ + ([[CL:​Macros:​defvar]] *temp1* 1) <​r>​*TEMP1*​ + ([[CL:​Macros:​defvar]] *temp2* 1) <​r>​*TEMP2*​ + ([[CL:​Macros:​defvar]] *temp3* 1) <​r>​*TEMP3*​ + (and ([[CL:​Macros:​incf]] temp1) ([[CL:​Macros:​incf]] temp2) ([[CL:​Macros:​incf]] temp3)) 2 + (and ([[CL:​Functions:​eql]] 2 temp1) ([[CL:​Functions:​eql]] 2 temp2) ([[CL:​Functions:​eql]] 2 temp3)) <​r>//​[[CL:​Glossary:​true]]//​ + ([[CL:​Macros:​decf]] temp3) 1 + (and ([[CL:​Macros:​decf]] temp1) ([[CL:​Macros:​decf]] temp2) ([[CL:​Functions:​eq]] temp3 '​[[CL:​Constant Variables:​nil]]) ([[CL:​Macros:​decf]] temp3)) <​r>​[[CL:​Constant Variables:​t|NIL]] + (and ([[CL:​Functions:​eql]] temp1 temp2) ([[CL:​Functions:​eql]] temp2 temp3)) <​r>//​[[CL:​Glossary:​true]]//​ + (and) <​r>​[[CL:​Constant Variables:​t|T]] + ​ + + ====Affected By==== + None. + + ====Exceptional Situations==== + None. + + ====See Also==== + * **[[CL:​Macros:​cond|Macro COND]]** + * **[[CL:​Functions:​every|Function EVERY]]** + * **[[CL:​Special Operators:​if|Special Operator IF]]** + * **[[CL:​Macros:​or|Macro OR]]** + * **[[CL:​Macros:​when|Macro WHEN]]** + + ====Notes==== + <​blockquote>​ + (and //form//) ≡ (let () //form//) + (and //form1// //form2// ...) ≡ (when //form1// (and //form2// ...)) + ​ +