1
0
Fork 0
cl-sites/novaspec.org/cl/f_if.html
2025-02-05 18:52:26 +01:00

295 lines
No EOL
5.5 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>if | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_if.html"
><LINK REL="next" HREF="f_or.html" TYPE="text/html" TITLE="or"
><LINK REL="prev" HREF="f_cond.html" TYPE="text/html" TITLE="cond"
><LINK REL="up" HREF="5_3_Data_and_Control_Flow_Dictionary.html" TYPE="text/html" TITLE="5.3 Data and Control Flow Dictionary"
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
><SCRIPT SRC="dpans.js%3F3909942064"
></SCRIPT
><SCRIPT SRC="apropos.js%3F3909942064"
></SCRIPT
></HEAD
><BODY
><DIV
><DIV CLASS="topnav"
><DIV CLASS="breadcrumb"
><SPAN CLASS="breadcrumb-item"
><A HREF="index.html"
>Common Lisp Nova Spec</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="5_Data_and_Control_Flow.html"
>5. Data and Control Flow</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="5_3_Data_and_Control_Flow_Dictionary.html"
>5.3 Data and Control Flow Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_if.html"
>if</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_cond.html" CLASS="prev"
>&#8592;</A
><SPAN ID="apropos-label"
>Apropos </SPAN
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
><A HREF="f_or.html" CLASS="next"
>&#8594;</A
></DIV
><DIV ID="apropos-res"
></DIV
></DIV
></DIV
><DIV CLASS="matter"
><DIV CLASS="com"
><DIV CLASS="begincom"
><HR
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
><TR
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="if"
></SPAN
><B
>if</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Special</I
> <I
>Operator</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><P CLASS="j"
><B
>if</B
> <VAR CLASS="param"
>test-form</VAR
> <VAR CLASS="param"
>then-form</VAR
> [<VAR CLASS="param"
>else-form</VAR
>] <SPAN CLASS="arrow"
>&#8594;</SPAN
> {<VAR CLASS="param"
>result</VAR
>}*</P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>Test-form</VAR
> &#8212; a <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>Then-form</VAR
> &#8212; a <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>Else-form</VAR
> &#8212; a <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
>. The default is <SPAN CLASS="misc"
><B
>nil</B
></SPAN
>. </P
><P CLASS="j"
><VAR CLASS="param"
>results</VAR
> &#8212; if the <VAR CLASS="param"
>test-form</VAR
> <A HREF="26_1_Glossary.html#yield"
><EM CLASS="term"
>yielded</EM
></A
> <A HREF="26_1_Glossary.html#true"
><EM CLASS="term"
>true</EM
></A
>, the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
> returned by the <VAR CLASS="param"
>then-form</VAR
>; otherwise, the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
> returned by the <VAR CLASS="param"
>else-form</VAR
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
><A HREF="f_if.html" CLASS="specref"
><B
>if</B
></A
> allows the execution of a <A HREF="26_1_Glossary.html#form"
><EM CLASS="term"
>form</EM
></A
> to be dependent on a single <VAR CLASS="param"
>test-form</VAR
>. </P
><P CLASS="j"
>First <VAR CLASS="param"
>test-form</VAR
> is evaluated. If the result is <A HREF="26_1_Glossary.html#true"
><EM CLASS="term"
>true</EM
></A
>, then <VAR CLASS="param"
>then-form</VAR
> is selected; otherwise <VAR CLASS="param"
>else-form</VAR
> is selected. Whichever form is selected is then evaluated.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
> (if t 1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1
(if nil 1 2) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 2
(defun test ()
(dolist (truth-value '(t nil 1 (a b c)))
(if truth-value (print 'true) (print 'false))
(prin1 truth-value))) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> TEST
(test)
<SPAN CLASS="cmr"
>&#8883;</SPAN
> TRUE T
<SPAN CLASS="cmr"
>&#8883;</SPAN
> FALSE NIL
<SPAN CLASS="cmr"
>&#8883;</SPAN
> TRUE 1
<SPAN CLASS="cmr"
>&#8883;</SPAN
> TRUE (A B C)
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL</PRE
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_cond.html" CLASS="macref"
><B
>cond</B
></A
>, <A HREF="f_when.html" CLASS="macref"
><B
>unless</B
></A
>, <A HREF="f_when.html" CLASS="macref"
><B
>when</B
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><PRE CLASS="screen"
>(if <VAR CLASS="param"
>test-form</VAR
> <VAR CLASS="param"
>then-form</VAR
> <VAR CLASS="param"
>else-form</VAR
>)
<SPAN CLASS="cmsy"
><SPAN STYLE="font-size:16px;vertical-align:-2px"
>&#8801;</SPAN
></SPAN
> (cond (<VAR CLASS="param"
>test-form</VAR
> <VAR CLASS="param"
>then-form</VAR
>) (t <VAR CLASS="param"
>else-form</VAR
>))</PRE
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_cond.html" CLASS="prev"
>&#8592;</A
><A HREF="f_or.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>