User Tools


Differences

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

Link to this comparison view

cl:special_operators:if [2017/05/01 21:00] (current)
Line 1: Line 1:
 +====== Special Operator IF ======
 +
 +====Syntax====
 +  * **if** //test-form then-form [else-form]//​ → //​result''​*''//​
 +
 +====Arguments and Values====
 +  * //​test-form//​ - a //​[[CL:​Glossary:​form]]//​.
 +  * //​then-form//​ - a //​[[CL:​Glossary:​form]]//​.
 +  * //​else-form//​ - a //​[[CL:​Glossary:​form]]//​. The default is **[[CL:​Constant Variables:​nil]]**.
 +  * //results// - if the //​test-form//​ //​[[CL:​Glossary:​yield|yielded]]//​ //​[[CL:​Glossary:​true]]//,​ the //​[[CL:​Glossary:​value|values]]//​ returned by the //​then-form//;​ otherwise, the //​[[CL:​Glossary:​value|values]]//​ returned by the //​else-form//​.
 +
 +====Description====
 +**[[CL:​Special Operators:​if]]** allows the execution of a //​[[CL:​Glossary:​form]]//​ to be dependent on a single //​test-form//​.
 +
 +First //​test-form//​ is evaluated. If the result is //​[[CL:​Glossary:​true]]//,​ then //​then-form//​ is selected; otherwise //​else-form//​ is selected. Whichever form is selected is then evaluated.
 +
 +====Examples====
 +<​blockquote>​
 +(if [[CL:​Constant Variables:​t]] 1) <​r>​1</​r>​
 +(if [[CL:​Constant Variables:​nil]] 1 2) <​r>​2</​r>​
 +([[CL:​Macros:​defun]] test () 
 +  ([[CL:​Macros:​dolist]] (truth-value '​([[CL:​Constant Variables:​t]] [[CL:​Constant Variables:​nil]] 1 (a b c)))
 +    (if truth-value ​
 +        ([[CL:​Functions:​print]] 'true)
 +        ([[CL:​Functions:​print]] '​false))
 +    ([[CL:​Functions:​prin1]] truth-value))) <​r>​TEST </r>
 +(test)
 +<​o>​TRUE [[CL:​Constant Variables:​t|T]]
 +FALSE [[CL:​Constant Variables:​nil|NIL]]
 +TRUE 1
 +TRUE (A B C) </o>
 +<​r>​[[CL:​Constant Variables:​NIL]]</​r>​
 +</​blockquote>​
 +
 +====Affected By====
 +None.
 +
 +====Exceptional Situations====
 +None.
 +
 +====See Also====
 +  * **[[CL:​Macros:​cond|Macro COND]]**
 +  * **[[CL:​Macros:​unless|Macro UNLESS]]**
 +  * **[[CL:​Macros:​when|Macro WHEN]]**
 +
 +====Notes====
 +<​blockquote>​
 +(if //​test-form//​ //​then-form//​ //​else-form//​) ​
 +  ≡ (cond (//​test-form//​ //​then-form//​) (t //​else-form//​))
 +</​blockquote>​
 +