User Tools


Macro CHECK-TYPE

Syntax

  • check-type place typespec [string]nil

Arguments and Values

Description

check-type signals a correctable error of type type-error if the contents of place are not of the type typespec.

check-type can return only if the store-value restart is invoked, either explicitly from a handler or implicitly as one of the options offered by the debugger. If the store-value restart is invoked, check-type stores the new value that is the argument to the restart invocation (or that is prompted for interactively by the debugger) in place and starts over, checking the type of the new value and signaling another error if it is still not of the desired type.

The first time place is evaluated, it is evaluated by normal evaluation rules. It is later evaluated as a place if the type check fails and the store-value restart is used; see section {\secref\GenRefSubFormEval}.

string should be an English description of the type, starting with an indefinite article ("a" or "an"). If string is not supplied, it is computed automatically from typespec. The automatically generated message mentions place, its contents, and the desired type. An implementation may choose to generate a somewhat differently worded error message if it recognizes that place is of a particular form, such as one of the arguments to the function that called check-type. string is allowed because some applications of check-type may require a more specific description of what is wanted than can be generated automatically from typespec.

Examples

(defparameter *aardvarks* '(sam harry fred))

*AARDVARKS*

(check-type aardvarks (array * (3)))

Error: The value of AARDVARKS, (SAM HARRY FRED), is not a 3-long array. 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: #(SAM FRED HARRY)

NIL

*aardvarks*

#<ARRAY-T-3 13571>

(map 'list #'identity aardvarks)

(SAM FRED HARRY)

(defparameter *aardvark-count* 'foo)

*AARDVARK-COUNT*

(check-type aardvark-count (integer 0 *) "A positive integer")

Error: The value of AARDVARK-COUNT, FOO, is not a positive integer. To continue, type :CONTINUE followed by an option number: 1: Specify a value to use instead. 2: Top level. Debug> :continue 2

(defmacro define-adder (name amount) (check-type name (and symbol (not null)) "a name for an adder function") (check-type amount integer) `(defun ,name (x) (+ x ,amount)))

DEFINE-ADDER

(macroexpand '(define-adder add3 3))

(DEFUN ADD3 (x) (+ X 3))

(macroexpand '(define-adder 7 7))

Error: The value of NAME, 7, is not a name for an adder function. To continue, type :CONTINUE followed by an option number: 1: Specify a value to use instead. 2: Top level. Debug> :continue 1 Specify a value to use instead. Type a form to be evaluated and used instead: 'ADD7

(DEFUN ADD7 (X) (+ X 7))

(macroexpand '(define-adder add5 something))

Error: The value of AMOUNT, SOMETHING, is not an integer. To continue, type :CONTINUE followed by an option number: 1: Specify a value to use instead. 2: Top level. Debug> continue 1 Type a form to be evaluated and used instead: 5

(DEFUN ADD5 (X) (+ X 5))

Side Effects

The debugger might be entered.

Affected By

*break-on-signals*

The implementation.

Exceptional Situations

None.

See Also

{\secref\ConditionSystemConcepts}

Notes

(check-type place typespec) ≡ (assert (typep place 'typespec) (place) 'type-error :datum place :expected-type 'typespec)