1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/m_and.htm
2024-04-01 10:24:07 +02:00

74 lines
5.1 KiB
HTML

<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Macro AND</TITLE>
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
<LINK REL=TOP HREF="../Front/index.htm">
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
<LINK REL=PREV HREF="f_everyc.htm">
<LINK REL=UP HREF="c_data_a.htm">
<LINK REL=NEXT HREF="m_cond.htm">
</HEAD>
<BODY>
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="f_everyc.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_data_a.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="m_cond.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="and"><I>Macro</I> <B>AND</B></A> <P>
<P><B>Syntax:</B><P>
<P>
<B>and</B> <I><I>form</I><B>*</B></I> =&gt; <I><I>result</I><B>*</B></I><P>
<P>
<P><B>Arguments and Values:</B><P>
<P>
<I>form</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A>. <P>
<I>results</I>---the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>values</I></A> resulting from the evaluation of the last <I>form</I>, or the symbols <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A> or <A REL=DEFINITION HREF="a_t.htm#t"><B>t</B></A>. <P>
<P><B>Description:</B><P>
<P>
The macro <A REL=DEFINITION HREF="#and"><B>and</B></A> evaluates each <I>form</I> one at a time from left to right. As soon as any <I>form</I> evaluates to <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>, <A REL=DEFINITION HREF="#and"><B>and</B></A> returns <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A> without evaluating the remaining <I>forms</I>. If all <I>forms</I> but the last evaluate to <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A> values, <A REL=DEFINITION HREF="#and"><B>and</B></A> returns the results produced by evaluating the last <I>form</I>. <P>
If no <I>forms</I> are supplied, <TT>(and)</TT> returns <A REL=DEFINITION HREF="a_t.htm#t"><B>t</B></A>. <P>
<A REL=DEFINITION HREF="#and"><B>and</B></A> passes back multiple values from the last <A REL=DEFINITION HREF="26_glo_s.htm#subform"><I>subform</I></A> but not from subforms other than the last. <P>
<P><B>Examples:</B><P>
<P>
<PRE>
(if (and (&gt;= n 0)
(&lt; n (length a-simple-vector))
(eq (elt a-simple-vector n) 'foo))
(princ &quot;Foo!&quot;))
</PRE>
</TT> The above expression prints <TT>Foo!</TT> if element <TT>n</TT> of <TT>a-simple-vector</TT> is the symbol <TT>foo</TT>, provided also that <TT>n</TT> is indeed a valid index for <TT>a-simple-vector</TT>. Because <A REL=DEFINITION HREF="#and"><B>and</B></A> guarantees left-to-right testing of its parts, <A REL=DEFINITION HREF="f_elt.htm#elt"><B>elt</B></A> is not called if <TT>n</TT> is out of range. <P>
<PRE>
(setq temp1 1 temp2 1 temp3 1) =&gt; 1
(and (incf temp1) (incf temp2) (incf temp3)) =&gt; 2
(and (eql 2 temp1) (eql 2 temp2) (eql 2 temp3)) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(decf temp3) =&gt; 1
(and (decf temp1) (decf temp2) (eq temp3 'nil) (decf temp3)) =&gt; NIL
(and (eql temp1 temp2) (eql temp2 temp3)) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(and) =&gt; T
</PRE>
</TT> <P>
<P><B>Affected By:</B> None.
<P>
<P><B>Exceptional Situations:</B> None.
<P>
<P><B>See Also:</B><P>
<P>
<A REL=DEFINITION HREF="m_cond.htm#cond"><B>cond</B></A>, <A REL=DEFINITION HREF="f_everyc.htm#every"><B>every</B></A>, <A REL=DEFINITION HREF="s_if.htm#if"><B>if</B></A>, <A REL=DEFINITION HREF="m_or.htm#or"><B>or</B></A>, <A REL=DEFINITION HREF="m_when_.htm#when"><B>when</B></A> <P>
<P><B>Notes:</B><P>
<P>
<PRE>
(and form) == (let () form)
(and form1 form2 ...) == (when form1 (and form2 ...))
</PRE>
</TT> <P>
<HR>
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
</BODY>
</HTML>