You are looking at historical revision 19112 of this page. It may differ significantly from its current revision.
check-errors
Argument checks, errors & conditions.
- check-errors
- Documentation
- Type Checks
- Usage
- check-fixnum
- check-positive-fixnum
- check-cardinal-fixnum
- check-flonum
- check-integer
- check-positive-integer
- check-cardinal-integer
- check-number
- check-positive-number
- check-cardinal-number
- check-procedure
- check-input-port
- check-output-port
- check-list
- check-pair
- check-blob
- check-vector
- check-structure
- check-symbol
- check-keyword
- check-string
- check-char
- check-boolean
- check-alist
- check-minimum-argument-count
- check-argument-count
- check-open-interval
- check-closed-interval
- check-half-open-interval
- check-half-closed-interval
- define-check-type
- define-check+error-type
- Type Errors
- Usage
- make-error-type-message
- signal-type-error
- error-argument-type
- warning-argument-type
- error-fixnum
- error-positive-fixnum
- error-cardinal-fixnum
- error-flonum
- error-integer
- error-positive-integer
- error-cardinal-integer
- error-number
- error-positive-number
- error-cardinal-number
- error-procedure
- error-input-port
- error-output-port
- error-list
- error-pair
- error-blob
- error-vector
- error-structure
- error-symbol
- error-keyword
- error-string
- error-char
- error-boolean
- error-alist
- error-minimum-argument-count
- error-argument-count
- error-open-interval
- error-closed-interval
- error-half-open-interval
- error-half-closed-interval
- define-error-type
- Conditions
- SRFI 4 Checks
- SRFI 4 Errors
- Type Checks
- Notes
- Author
- Version history
- License
Documentation
Type Checks
Performs the minimal constraint check and raises an error condition upon failure. The mimimal constraint proviso is important for understanding the behavior of the checking routines. Unless otherwise specified no additional constraints are verified.
So the check-...-interval routines, for example, do not verify the types of the arugments, only the interval constraint.
When the unsafe feature is defined the check procedures are no-ops.
Usage
(require-extension type-checks)
check-fixnum
[procedure] (check-fixnum LOCATION OBJECT [ARGUMENT-NAME])check-positive-fixnum
[procedure] (check-positive-fixnum LOCATION OBJECT [ARGUMENT-NAME])check-cardinal-fixnum
[procedure] (check-cardinal-fixnum LOCATION OBJECT [ARGUMENT-NAME])check-flonum
[procedure] (check-flonum LOCATION OBJECT [ARGUMENT-NAME])check-integer
[procedure] (check-integer LOCATION OBJECT [ARGUMENT-NAME])check-positive-integer
[procedure] (check-positive-integer LOCATION OBJECT [ARGUMENT-NAME])check-cardinal-integer
[procedure] (check-cardinal-integer LOCATION OBJECT [ARGUMENT-NAME])check-number
[procedure] (check-number LOCATION OBJECT [ARGUMENT-NAME])check-positive-number
[procedure] (check-positive-number LOCATION OBJECT [ARGUMENT-NAME])check-cardinal-number
[procedure] (check-cardinal-number LOCATION OBJECT [ARGUMENT-NAME])check-procedure
[procedure] (check-procedure LOCATION OBJECT [ARGUMENT-NAME])check-input-port
[procedure] (check-input-port LOCATION OBJECT [ARGUMENT-NAME])check-output-port
[procedure] (check-output-port LOCATION OBJECT [ARGUMENT-NAME])check-list
[procedure] (check-list LOCATION OBJECT [ARGUMENT-NAME])check-pair
[procedure] (check-pair LOCATION OBJECT [ARGUMENT-NAME])check-blob
[procedure] (check-blob LOCATION OBJECT [ARGUMENT-NAME])check-vector
[procedure] (check-vector LOCATION OBJECT [ARGUMENT-NAME])check-structure
[procedure] (check-structure LOCATION OBJECT TAG [ARGUMENT-NAME])check-record and check-record-type are essentially synonyms.
check-symbol
[procedure] (check-symbol LOCATION OBJECT [ARGUMENT-NAME])check-keyword
[procedure] (check-keyword LOCATION OBJECT [ARGUMENT-NAME])check-string
[procedure] (check-string LOCATION OBJECT [ARGUMENT-NAME])check-char
[procedure] (check-char LOCATION OBJECT [ARGUMENT-NAME])check-boolean
[procedure] (check-boolean LOCATION OBJECT [ARGUMENT-NAME])check-alist
[procedure] (check-alist LOCATION OBJECT [ARGUMENT-NAME])check-minimum-argument-count
[procedure] (check-minimum-argument-count LOCATION ARGC MINARGC)check-argument-count
[procedure] (check-argument-count LOCATION ARGC MAXARGC)check-open-interval
[procedure] (check-open-interval LOCATION NUM MINNUM MAXNUM)NUM in ]MINNUM MAXNUM[.
check-closed-interval
[procedure] (check-closed-interval LOCATION NUM MINNUM MAXNUM)NUM in [MINNUM MAXNUM].
check-half-open-interval
[procedure] (check-half-open-interval LOCATION NUM MINNUM MAXNUM)NUM in ]MINNUM MAXNUM].
check-half-closed-interval
[procedure] (check-half-closed-interval LOCATION NUM MINNUM MAXNUM)NUM in [MINNUM MAXNUM[.
define-check-type
[syntax] (define-check-type TYPE [PREDICATE])Creates a procedure definition for check-TYPE with the signature of the above check procedures. The predicate is either PREDICATE, when present, or TYPE?.
(define-check-type hash-table) ;=> ;(define (check-hash-table loc obj #!optional argnam) ; (unless (hash-table? obj) ; (error-hash-table loc obj argnam)) ; obj )
define-check+error-type
[syntax] (define-check+error-type TYPE [PREDICATE [TYPE-NAME]])Creates a procedure definition for check-TYPE with the signature of the above check procedures. The predicate is either PREDICATE, when present, or TYPE?. The error message type-name is either the TYPE-NAME, when present, or "TYPE".
(define-check+error-type hash-table) ;=> ;(define-error-type loc obj #!optional argnam) ; (define (check-hash-table loc obj #!optional argnam) ; (unless (hash-table? obj) ; (error-hash-table loc obj argnam)) ; obj )
Type Errors
Usage
(require-extension type-errors)
make-error-type-message
[procedure] (make-error-type-message TYPE-NAME [ARGUMENT-NAME]) => STRINGTYPE-NAME and ARGUMENT-NAME are a symbol or string.
Returns a type error message from the TYPE-NAME and optional ARGUMENT-NAME.
Example:
(make-error-type-message 'integer "count") ;=> "bad `count' argument type - not an integer"
signal-type-error
[procedure] (signal-type-error LOCATION MESSAGE OBJECT...)Raises a non-continuable type error - (({exn type)}}.
error-argument-type
[procedure] (error-argument-type LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])TYPE-NAME is a symbol or string. ARGUMENT-NAME is a string.
Raises a type-error where is message is constructed from the TYPE-NAME and optional ARGUMENT-NAME.
warning-argument-type
[procedure] (warning-argument-type LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])A warning is issued with a message similar to that of error-argument-type.
error-fixnum
[procedure] (error-fixnum LOCATION OBJECT [ARGUMENT-NAME])error-positive-fixnum
[procedure] (error-positive-fixnum LOCATION OBJECT [ARGUMENT-NAME])error-cardinal-fixnum
[procedure] (error-cardinal-fixnum LOCATION OBJECT [ARGUMENT-NAME])error-flonum
[procedure] (error-flonum LOCATION OBJECT [ARGUMENT-NAME])error-integer
[procedure] (error-integer LOCATION OBJECT [ARGUMENT-NAME])error-positive-integer
[procedure] (error-positive-integer LOCATION OBJECT [ARGUMENT-NAME])error-cardinal-integer
[procedure] (error-cardinal-integer LOCATION OBJECT [ARGUMENT-NAME])error-number
[procedure] (error-number LOCATION OBJECT [ARGUMENT-NAME])error-positive-number
[procedure] (error-positive-number LOCATION OBJECT [ARGUMENT-NAME])error-cardinal-number
[procedure] (error-cardinal-number LOCATION OBJECT [ARGUMENT-NAME])error-procedure
[procedure] (error-procedure LOCATION OBJECT [ARGUMENT-NAME])error-input-port
[procedure] (error-input-port LOCATION OBJECT [ARGUMENT-NAME])error-output-port
[procedure] (error-output-port LOCATION OBJECT [ARGUMENT-NAME])error-list
[procedure] (error-list LOCATION OBJECT [ARGUMENT-NAME])error-pair
[procedure] (error-pair LOCATION OBJECT [ARGUMENT-NAME])error-blob
[procedure] (error-blob LOCATION OBJECT [ARGUMENT-NAME])error-vector
[procedure] (error-vector LOCATION OBJECT [ARGUMENT-NAME])error-structure
[procedure] (error-structure LOCATION OBJECT TAG [ARGUMENT-NAME])error-record and error-record-type are essentially synonyms.
error-symbol
[procedure] (error-symbol LOCATION OBJECT [ARGUMENT-NAME])error-keyword
[procedure] (error-keyword LOCATION OBJECT [ARGUMENT-NAME])error-string
[procedure] (error-string LOCATION OBJECT [ARGUMENT-NAME])error-char
[procedure] (error-char LOCATION OBJECT [ARGUMENT-NAME])error-boolean
[procedure] (error-boolean LOCATION OBJECT [ARGUMENT-NAME])error-alist
[procedure] (error-alist LOCATION OBJECT [ARGUMENT-NAME])error-minimum-argument-count
[procedure] (error-minimum-argument-count LOCATION ARGC MINARGC)error-argument-count
[procedure] (error-argument-count LOCATION ARGC MAXARGC)error-open-interval
[procedure] (error-open-interval LOCATION NUM MINNUM MAXNUM)error-closed-interval
[procedure] (error-closed-interval LOCATION NUM MINNUM MAXNUM)error-half-open-interval
[procedure] (error-half-open-interval LOCATION NUM MINNUM MAXNUM)error-half-closed-interval
[procedure] (error-half-closed-interval LOCATION NUM MINNUM MAXNUM)define-error-type
[syntax] (define-error-type TYPE [MESSAGE])Creates a procedure definition for error-TYPE with the signature of the above error procedures. The error message is either MESSAGE, when present, or "TYPE".
(define-error-type hash-table) ;=> (define (error-hash-table loc obj #!optional argnam) ; (error-argument-type loc obj "hash-table" argnam) )
Conditions
Usage
(require-extension conditions)
make-exn-condition
[procedure] (make-exn-condition LOCATION MESSAGE ARGUMENTS) => PROPERTY-CONDITIONLOCATION is a symbol.
MESSAGE is a string.
ARGUMENTS is a list.
LOCATION, MESSAGE and ARGUMENTS maybe #f.
Returns an exn property-condition with optional location, message and arguments properties.
make-exn-condition+
[procedure] (make-exn-condition+ LOCATION MESSAGE ARGUMENTS [CONDITION...]) => PROPERTY-CONDITIONLOCATION, MESSAGE and ARGUMENTS as make-exn-condition.
CONDITION is a:
- property-condition
- literal
- symbol
- (make-property-condition <symbol>)
- list
- (apply make-property-condition <list>)
Returns a composite-condition exn CONDITION....
make-condition+
[procedure] (make-condition+ CONDITION...) => PROPERTY-CONDITIONCONDITION as make-exn-condition+
Returns a composite-condition CONDITION....
condition-predicate*
[procedure] (condition-predicate* KIND) => PROCEDURE/1Returns a "memioized" condition-predicate for KIND.
KIND is a symbol.
make-condition-predicate
[syntax] (make-condition-predicate KIND...) => PROCEDURE/1Returns a condition-predicate for KIND....
KIND is a symbol.
condition-property-accessor*
[procedure] (condition-property-accessor* KIND PROP [DEFAULT]) => PROCEDURE/1Returns a "memioized" condition-property-accessor for KIND.
KIND and PROP are symbol.
make-condition-property-accessor
[syntax] (make-condition-property-accessor KIND PROP [DEFAULT]) => PROCEDURE/1Returns a condition-property-accessor for KIND PROP.
KIND and PROP are symbol.
SRFI 4 Checks
Usage
(require-extension srfi-4-checks)
check-s8vector
[procedure] (check-s8vector LOCATION OBJECT [ARGUMENT-NAME])check-u8vector
[procedure] (check-u8vector LOCATION OBJECT [ARGUMENT-NAME])check-s16vector
[procedure] (check-s16vector LOCATION OBJECT [ARGUMENT-NAME])check-u16vector
[procedure] (check-u16vector LOCATION OBJECT [ARGUMENT-NAME])check-s32vector
[procedure] (check-s32vector LOCATION OBJECT [ARGUMENT-NAME])check-u32vector
[procedure] (check-u32vector LOCATION OBJECT [ARGUMENT-NAME])check-f32vector
[procedure] (check-f32vector LOCATION OBJECT [ARGUMENT-NAME])check-f64vector
[procedure] (check-f64vector LOCATION OBJECT [ARGUMENT-NAME])SRFI 4 Errors
Usage
(require-extension srfi-4-errors)
error-s8vector
[procedure] (error-s8vector LOCATION OBJECT [ARGUMENT-NAME])error-u8vector
[procedure] (error-u8vector LOCATION OBJECT [ARGUMENT-NAME])error-s16vector
[procedure] (error-s16vector LOCATION OBJECT [ARGUMENT-NAME])error-u16vector
[procedure] (error-u16vector LOCATION OBJECT [ARGUMENT-NAME])error-s32vector
[procedure] (error-s32vector LOCATION OBJECT [ARGUMENT-NAME])error-u32vector
[procedure] (error-u32vector LOCATION OBJECT [ARGUMENT-NAME])error-f32vector
[procedure] (error-f32vector LOCATION OBJECT [ARGUMENT-NAME])error-f64vector
[procedure] (error-f64vector LOCATION OBJECT [ARGUMENT-NAME])Notes
- s64vector and u64vector are not supported; unsupported by Chicken SRFI 4.
Author
Version history
- 1.10.0 ; The check-... routines return the checked value.
- 1.8.0
- Added srfi-4 support.
- 1.7.0
- 1.6.0
- Added interval support.
- 1.5.0
- Added alist and argument count support.
- 1.4.0
- 1.3.0
- Added warning-argument-type.
- 1.2.0
- Added make-error-type-message & fixed define-check+error-type.
- 1.1.0
- Added make-condition+, condition-property-accessor* and make-condition-property-accessor.
- 1.0.0
- Initial release.
License
Copyright (C) 2009 Kon Lovett. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.