/[emacs]/emacs/lispref/control.texi
ViewVC logotype

Diff of /emacs/lispref/control.texi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.17 by rms, Sun May 12 17:04:51 2002 UTC revision 1.17.2.1 by miles, Fri Apr 4 06:20:41 2003 UTC
# Line 1  Line 1 
1  @c -*-texinfo-*-  @c -*-texinfo-*-
2  @c This is part of the GNU Emacs Lisp Reference Manual.  @c This is part of the GNU Emacs Lisp Reference Manual.
3  @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999  @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
4  @c  Free Software Foundation, Inc.  @c  Free Software Foundation, Inc.
5  @c See the file elisp.texi for copying conditions.  @c See the file elisp.texi for copying conditions.
6  @setfilename ../info/control  @setfilename ../info/control
7  @node Control Structures, Variables, Evaluation, Top  @node Control Structures, Variables, Evaluation, Top
# Line 154  based on the value of @var{condition}. Line 154  based on the value of @var{condition}.
154  non-@code{nil}, @var{then-form} is evaluated and the result returned.  non-@code{nil}, @var{then-form} is evaluated and the result returned.
155  Otherwise, the @var{else-forms} are evaluated in textual order, and the  Otherwise, the @var{else-forms} are evaluated in textual order, and the
156  value of the last one is returned.  (The @var{else} part of @code{if} is  value of the last one is returned.  (The @var{else} part of @code{if} is
157  an example of an implicit @code{progn}.  @xref{Sequencing}.)  an example of an implicit @code{progn}.  @xref{Sequencing}.)
158    
159  If @var{condition} has the value @code{nil}, and no @var{else-forms} are  If @var{condition} has the value @code{nil}, and no @var{else-forms} are
160  given, @code{if} returns @code{nil}.  given, @code{if} returns @code{nil}.
# Line 165  never evaluated---it is ignored.  Thus, Line 165  never evaluated---it is ignored.  Thus,
165    
166  @example  @example
167  @group  @group
168  (if nil  (if nil
169      (print 'true)      (print 'true)
170    'very-false)    'very-false)
171  @result{} very-false  @result{} very-false
172  @end group  @end group
# Line 260  clauses was successful.  To do this, we Line 260  clauses was successful.  To do this, we
260  never @code{nil}, so this clause never fails, provided the @code{cond}  never @code{nil}, so this clause never fails, provided the @code{cond}
261  gets to it at all.  gets to it at all.
262    
263  For example,  For example,
264    
265  @example  @example
266  @group  @group
# Line 376  expression returns @code{nil}.  Just @co Line 376  expression returns @code{nil}.  Just @co
376  @var{conditions} turned out @code{nil}.  (Think about it; which one  @var{conditions} turned out @code{nil}.  (Think about it; which one
377  did not?)  did not?)
378    
379  For example, this expression tests whether @code{x} is either  For example, this expression tests whether @code{x} is either
380  @code{nil} or the integer zero:  @code{nil} or the integer zero:
381    
382  @example  @example
# Line 401  You could almost write @code{or} in term Line 401  You could almost write @code{or} in term
401  @example  @example
402  @group  @group
403  (if @var{arg1} @var{arg1}  (if @var{arg1} @var{arg1}
404    (if @var{arg2} @var{arg2}    (if @var{arg2} @var{arg2}
405      @var{arg3}))      @var{arg3}))
406  @end group  @end group
407  @end example  @end example
# Line 663  return points at once.  First, two retur Line 663  return points at once.  First, two retur
663  @end group  @end group
664    
665  @group  @group
666  (catch 'hack  (catch 'hack
667    (print (catch2 'hack))    (print (catch2 'hack))
668    'no)    'no)
669  @print{} yes  @print{} yes
# Line 745  which you call for other purposes, such Line 745  which you call for other purposes, such
745  buffer.  You can also signal errors explicitly with the functions  buffer.  You can also signal errors explicitly with the functions
746  @code{error} and @code{signal}.  @code{error} and @code{signal}.
747    
748    Quitting, which happens when the user types @kbd{C-g}, is not    Quitting, which happens when the user types @kbd{C-g}, is not
749  considered an error, but it is handled almost like an error.  considered an error, but it is handled almost like an error.
750  @xref{Quitting}.  @xref{Quitting}.
751    
# Line 1000  message (but without a beep), then retur Line 1000  message (but without a beep), then retur
1000  @smallexample  @smallexample
1001  @group  @group
1002  (defun safe-divide (dividend divisor)  (defun safe-divide (dividend divisor)
1003    (condition-case err                    (condition-case err
1004        ;; @r{Protected form.}        ;; @r{Protected form.}
1005        (/ dividend divisor)                      (/ dividend divisor)
1006  @end group  @end group
1007  @group  @group
1008      ;; @r{The handler.}      ;; @r{The handler.}
# Line 1046  including those signaled with @code{erro Line 1046  including those signaled with @code{erro
1046        ;; @r{This is a call to the function @code{error}.}        ;; @r{This is a call to the function @code{error}.}
1047        (error "Rats!  The variable %s was %s, not 35" 'baz baz))        (error "Rats!  The variable %s was %s, not 35" 'baz baz))
1048    ;; @r{This is the handler; it is not a form.}    ;; @r{This is the handler; it is not a form.}
1049    (error (princ (format "The error was: %s" err))    (error (princ (format "The error was: %s" err))
1050           2))           2))
1051  @print{} The error was: (error "Rats!  The variable baz was 34, not 35")  @print{} The error was: (error "Rats!  The variable baz was 34, not 35")
1052  @result{} 2  @result{} 2
# Line 1096  message @samp{peculiar error} is used. Line 1096  message @samp{peculiar error} is used.
1096  @group  @group
1097  (put 'new-error  (put 'new-error
1098       'error-conditions       'error-conditions
1099       '(error my-own-errors new-error))             '(error my-own-errors new-error))
1100  @result{} (error my-own-errors new-error)  @result{} (error my-own-errors new-error)
1101  @end group  @end group
1102  @group  @group
# Line 1112  classification; and @code{error}, which Line 1112  classification; and @code{error}, which
1112    
1113    The error string should start with a capital letter but it should    The error string should start with a capital letter but it should
1114  not end with a period.  This is for consistency with the rest of Emacs.  not end with a period.  This is for consistency with the rest of Emacs.
1115    
1116    Naturally, Emacs will never signal @code{new-error} on its own; only    Naturally, Emacs will never signal @code{new-error} on its own; only
1117  an explicit call to @code{signal} (@pxref{Signaling Errors}) in your  an explicit call to @code{signal} (@pxref{Signaling Errors}) in your
1118  code can do this:  code can do this:

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.17.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26