This shows you the differences between two versions of the page.
cl:functions:type-error-datum [2019/09/14 05:00] |
cl:functions:type-error-datum [2021/01/20 18:00] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Function TYPE-ERROR-DATUM, TYPE-ERROR-EXPECTED-TYPE ====== | ||
+ | |||
+ | ====Syntax==== | ||
+ | * **type-error-datum** //condition// → //datum// | ||
+ | * **type-error-expected-type** //condition// → //expected-type// | ||
+ | |||
+ | ====Arguments and Values==== | ||
+ | * //condition// - a //[[CL:Glossary:condition]]// of type **[[CL:Types:type-error]]**. | ||
+ | * //datum// - an //[[CL:Glossary:object]]//. | ||
+ | * //expected-type// - a //[[CL:Glossary:type specifier]]//. | ||
+ | |||
+ | ====Description==== | ||
+ | **type-error-datum** returns the offending datum in the //[[CL:Glossary:situation]]// represented by the //condition//. | ||
+ | |||
+ | **type-error-expected-type** returns the expected type of the offending datum in the //[[CL:Glossary:situation]]// represented by the //condition//. | ||
+ | |||
+ | ====Examples==== | ||
+ | <blockquote> | ||
+ | ;;; TODO fix this so this doesn't always store 7 but val instead | ||
+ | ([[CL:Macros:defun]] fix-digits (condition) | ||
+ | ([[CL:Macros:check-type]] condition [[CL:Types:type-error]]) | ||
+ | ([[CL:Special Operators:let*]] ((digits '(zero one two three four five six seven eight nine)) | ||
+ | (val ([[CL:Functions:position]] (type-error-datum condition) digits))) | ||
+ | ([[CL:Special Operators:if]] ([[CL:Macros:and]] val ([[CL:Functions:subtypep]] 'fixnum (type-error-expected-type condition))) | ||
+ | ([[CL:Functions:store-value]] 7)))) <r>FIX-DIGITS</r> | ||
+ | |||
+ | ([[CL:Macros:defun]] foo (x) | ||
+ | ([[CL:Macros:handler-bind]] (([[CL:Types:type-error]] #'fix-digits)) | ||
+ | ([[CL:Macros:check-type]] x [[CL:Types:number]]) | ||
+ | ([[CL:Functions:math-add|+]] x 3))) <r>FOO</r> | ||
+ | |||
+ | (foo 'seven) <r>10 </r> | ||
+ | </blockquote> | ||
+ | |||
+ | ====Side Effects==== | ||
+ | None. | ||
+ | |||
+ | ====Affected By==== | ||
+ | None. | ||
+ | |||
+ | ====Exceptional Situations==== | ||
+ | None. | ||
+ | |||
+ | ====See Also==== | ||
+ | * **[[CL:Types:type-error|Condition Type TYPE-ERROR]]** | ||
+ | * {\secref\Conditions} | ||
+ | |||
+ | ====Notes==== | ||
+ | None. | ||
+ | |||