Common Lisp the Language, 2nd Edition
![]()
Next: Handling Conditions
Up: Program Interface to
Previous: Assertions

The syntax for etypecase and ctypecase is the
same as for typecase, except that no otherwise
clause is permitted. Similarly, the syntax for ecase and
ccase is the same as for case except for the
otherwise clause.
etypecase and ecase are similar to
typecase and case, respectively, but signal a
non-continuable error rather than returning nil if no
clause is selected.
ctypecase and ccase are also similar to
typecase and case, respectively, but signal a
continuable error if no clause is selected.
[Macro]
etypecasekeyform{(type{form}*)}*
[This supersedes the description of etypecase given in
section 24.3.-GLS]
This control construct is similar to typecase, but no
explicit otherwise or t clause is permitted.
If no clause is satisfied, etypecase signals an error (of
type type-error) with a message constructed from the
clauses. It is not permissible to continue from this error. To supply an
error message, the user should use typecase with an
otherwise clause containing a call to error.
The name of this function stands for ``exhaustive type case’’ or
``error-checking type case.’’
Example:
Lisp> (setq x 1/3)
=> 1/3
Lisp> (etypecase x
(integer (* x 4))
(symbol (symbol-value x)))
Error: The value of X, 1/3, is neither an integer nor a symbol.
To continue, type :CONTINUE followed by an option number:
1: Return to Lisp Toplevel.
Debug>
[Macro]
ctypecasekeyplace{(type{form}*)}*
[This supersedes the description of ctypecase given in
section 24.3.-GLS]
This control construct is similar to typecase, but no
explicit otherwise or t clause is
permitted.
The keyplace must be a generalized variable reference
acceptable to setf. If no clause is satisfied,
ctypecase signals an error (of type
type-error) with a message constructed from the clauses.
This error may be continued using the store-value restart.
The argument to store-value is stored in keyplace
and then ctypecase starts over, making the type tests
again. Subforms of keyplace may be evaluated multiple times. If
the store-value restart is invoked interactively, the user
will be prompted for the value to be used.
The name of this function is mnemonic for ``continuable (exhaustive) type case.’’
Example:
Lisp> (setq x 1/3)
=> 1/3
Lisp> (ctypecase x
(integer (* x 4))
(symbol (symbol-value x)))
Error: The value of X, 1/3, is neither an integer nor a symbol.
To continue, type :CONTINUE followed by an option number:
1: Specify a value to use instead.
2: Return to Lisp Toplevel.
Debug> :continue 1
Use value: 3.7
Error: The value of X, 3.7, is neither an integer nor a symbol.
To continue, type :CONTINUE followed by an option number:
1: Specify a value to use instead.
2: Return to Lisp Toplevel.
Debug> :continue 1
Use value: 12
=> 48
[Macro]
ecasekeyform{({({key}*) |key} {form}*)}*
[This supersedes the description of ecase given in
section 24.3.-GLS]
This control construct is similar to case, but no
explicit otherwise or t clause is permitted.
If no clause is satisfied, ecase signals an error (of type
type-error) with a message constructed from the clauses. It
is not permissible to continue from this error. To supply an error
message, the user should use case with an
otherwise clause containing a call to error.
The name of this function stands for ``exhaustive case’’ or
``error-checking case.’’
Example:
Lisp> (setq x 1/3)
=> 1/3
Lisp> (ecase x
(alpha (foo))
(omega (bar))
((zeta phi) (baz)))
Error: The value of X, 1/3, is not ALPHA, OMEGA, ZETA, or PHI.
To continue, type :CONTINUE followed by an option number:
1: Return to Lisp Toplevel.
Debug>
[Macro]
ccasekeyplace{({({key}*) |key} {form}*)}*
[This supersedes the description of ccase given in
section 24.3.-GLS]
This control construct is similar to case, but no
explicit otherwise or t clause is
permitted.
The keyplace must be a generalized variable reference
acceptable to setf. If no clause is satisfied,
ccase signals an error (of type type-error)
with a message constructed from the clauses. This error may be continued
using the store-value restart. The argument to
store-value is stored in keyplace and then
ccase starts over, making the type tests again. Subforms of
keyplace may be evaluated multiple times. If the
store-value restart is invoked interactively, the user will
be prompted for the value to be used.
The name of this function is mnemonic for ``continuable (exhaustive) case.’’
Implementation note: The type-error
signaled by ccase and ecase is free to choose
any representation of the acceptable argument type that it wishes for
placement in the expected-type slot. It will always work to use type
(member .keys), but in
some cases it may be more efficient, for example, to use a type that
represents an integer subrange or a type composed using the
or type specifier.
![]()
Next: Handling Conditions
Up: Program Interface to
Previous: Assertions
AI.Repository@cs.cmu.edu