comparison lispref/control.texi @ 16850:ee4b53003fd5

Add when and unless.
author Richard M. Stallman <rms@gnu.org>
date Thu, 09 Jan 1997 07:58:14 +0000
parents 981e116b4ac6
children 66d807bdc5b4
comparison
equal deleted inserted replaced
16849:ec7768e50ba8 16850:ee4b53003fd5
141 @node Conditionals 141 @node Conditionals
142 @section Conditionals 142 @section Conditionals
143 @cindex conditional evaluation 143 @cindex conditional evaluation
144 144
145 Conditional control structures choose among alternatives. Emacs Lisp 145 Conditional control structures choose among alternatives. Emacs Lisp
146 has two conditional forms: @code{if}, which is much the same as in other 146 has four conditional forms: @code{if}, which is much the same as in
147 languages, and @code{cond}, which is a generalized case statement. 147 other languages; @code{when} and @code{unless}, which are variants of
148 @code{if}; and @code{cond}, which is a generalized case statement.
148 149
149 @defspec if condition then-form else-forms@dots{} 150 @defspec if condition then-form else-forms@dots{}
150 @code{if} chooses between the @var{then-form} and the @var{else-forms} 151 @code{if} chooses between the @var{then-form} and the @var{else-forms}
151 based on the value of @var{condition}. If the evaluated @var{condition} is 152 based on the value of @var{condition}. If the evaluated @var{condition} is
152 non-@code{nil}, @var{then-form} is evaluated and the result returned. 153 non-@code{nil}, @var{then-form} is evaluated and the result returned.
166 (if nil 167 (if nil
167 (print 'true) 168 (print 'true)
168 'very-false) 169 'very-false)
169 @result{} very-false 170 @result{} very-false
170 @end group 171 @end group
172 @end example
173 @end defspec
174
175 @defspec when condition then-forms@dots{}
176 This is a variant of @code{if} where there are no @var{else-forms},
177 and possibly several @var{then-forms}. In particular,
178
179 @example
180 (when @var{condition} @var{a} @var{b} @var{c})
181 @end example
182
183 @noindent
184 is entirely equivalent to
185
186 @example
187 (if @var{condition} (progn @var{a} @var{b} @var{c}) nil)
188 @end example
189 @end defspec
190
191 @defspec unless condition forms@dots{}
192 This is a variant of @code{if} where there is no @var{then-form}:
193
194 @example
195 (unless @var{condition} @var{a} @var{b} @var{c})
196 @end example
197
198 @noindent
199 is entirely equivalent to
200
201 @example
202 (if @var{condition} nil
203 @var{a} @var{b} @var{c})
171 @end example 204 @end example
172 @end defspec 205 @end defspec
173 206
174 @defspec cond clause@dots{} 207 @defspec cond clause@dots{}
175 @code{cond} chooses among an arbitrary number of alternatives. Each 208 @code{cond} chooses among an arbitrary number of alternatives. Each