chickadee » check-errors

check-errors

Argument checks & errors.

TOC »

Documentation

Argument Conventions

LOC is a symbol, or #f. The symbolic naming of the location detecting the problem. As in the error form.

OBJ is any Scheme object.

ARGNAM is a string or symbol naming the argument list element corresponding to the OBJ. The default is the type-name.

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 arguments, only the interval constraint.

When the unsafe feature is defined the check procedures are no-ops.

Note that the full-numeric-tower is not supported.

All check-... routines return the checked object; unless a type-error exception is raised, obviously.

Usage

(require-extension type-checks)

check-defined-value

check-defined-value LOC OBJ #!optional ARGNAMprocedure

Ensures the OBJ is non-void, i.e. not an undefined-value.

check-bound-value

check-bound-value LOC OBJ #!optional ARGNAMprocedure

Ensures the OBJ is the value of a bound variable.

Only for use in rather unsafe calling environments where some explicit checking is necessary.

check-fixnum

check-fixnum LOC OBJ #!optional ARGNAMprocedure

check-positive-fixnum

check-positive-fixnum LOC OBJ #!optional ARGNAMprocedure

check-natural-fixnum

check-natural-fixnum LOC OBJ #!optional ARGNAMprocedure

check-flonum

check-flonum LOC OBJ #!optional ARGNAMprocedure

check-integer

check-integer LOC OBJ #!optional ARGNAMprocedure

check-positive-integer

check-positive-integer LOC OBJ #!optional ARGNAMprocedure

check-natural-integer

check-natural-integer LOC OBJ #!optional ARGNAMprocedure

check-number

check-number LOC OBJ #!optional ARGNAMprocedure

check-positive-number

check-positive-number LOC OBJ #!optional ARGNAMprocedure

check-natural-number

check-natural-number LOC OBJ #!optional ARGNAMprocedure

check-procedure

check-procedure LOC OBJ #!optional ARGNAMprocedure

check-input-port

check-input-port LOC OBJ #!optional ARGNAMprocedure

check-output-port

check-output-port LOC OBJ #!optional ARGNAMprocedure

check-list

check-list LOC OBJ #!optional ARGNAMprocedure

check-pair

check-pair LOC OBJ #!optional ARGNAMprocedure

check-blob

check-blob LOC OBJ #!optional ARGNAMprocedure

check-vector

check-vector LOC OBJ #!optional ARGNAMprocedure

check-structure

check-structure LOC OBJ TAG #!optional ARGNAMprocedure
check-record LOC OBJ TAG #!optional ARGNAMprocedure
check-record-type LOC OBJ TAG #!optional ARGNAMprocedure

check-record and check-record-type are essentially synonyms.

check-symbol

check-symbol LOC OBJ #!optional ARGNAMprocedure

check-keyword

check-keyword LOC OBJ #!optional ARGNAMprocedure

check-string

check-string LOC OBJ #!optional ARGNAMprocedure

check-char

check-char LOC OBJ #!optional ARGNAMprocedure

check-boolean

check-boolean LOC OBJ #!optional ARGNAMprocedure

check-alist

check-alist LOC OBJ #!optional ARGNAMprocedure

check-minimum-argument-count

check-minimum-argument-count LOC ARGC MINARGCprocedure

Does not verify the type of ARGC, or MINARGC.

check-argument-count

check-argument-count LOC ARGC MAXARGCprocedure

Does not verify the type of ARGC, or MAXARGC.

check-open-interval

check-open-interval LOC NUM MINNUM MAXNUM #!optional ARGNAMprocedure

NUM in ]MINNUM MAXNUM[.

Does not verify the type of NUM, MINNUM, or MAXNUM.

check-closed-interval

check-closed-interval LOC NUM MINNUM MAXNUM #!optional ARGNAMprocedure

NUM in [MINNUM MAXNUM].

Does not verify the type of NUM, MINNUM, or MAXNUM.

check-half-open-interval

check-half-open-interval LOC NUM MINNUM MAXNUM #!optional ARGNAMprocedure

NUM in ]MINNUM MAXNUM].

Does not verify the type of NUM, MINNUM, or MAXNUM.

check-half-closed-interval

check-half-closed-interval LOC NUM MINNUM MAXNUM #!optional ARGNAMprocedure

NUM in [MINNUM MAXNUM[.

Does not verify the type of NUM, MINNUM, or MAXNUM.

define-check-type

(define-check-type TYPNAM [TYPE-PRED])syntax

Creates a procedure definition for check-TYPNAM} with the signature of the above check procedures. The type-predicate is either {{TYPE-PRED, when present, or TYPNAM?.

TYPNAM is an unquoted symbol.

(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

(define-check+error-type TYPNAM [TYPE-PRED [TYPMSG]])syntax

Creates a procedure definition for check-TYPNAM} with the signature of the above check procedures. The type-predicate is either {{TYPE-PRED, when present, or TYPE?. The error message type-name is either the TYPMSG, when present, or "TYPNAM"".

TYPNAM is an unquoted symbol.

(define-check+error-type hash-table)
;=>
;(define-error-type loc obj 'hash-table)
;(define (check-hash-table loc obj #!optional argnam)
;  (unless (hash-table? obj)
;    (error-hash-table loc obj argnam))
;  obj )

Type Errors

Argument Conventions

TYPNAM is a symbol or string, unless otherwise indicated.

ARGNAM is a symbol, string, or #f. Default is #f.

Usage

(require-extension type-errors)

make-bad-argument-message

make-bad-argument-message #!optional ARGNAMprocedure

Returns an argument type error message for the, optional, ARGNAM.

Example:

(make-bad-argument-message "count")
;=> "bad `count' argument"
(make-bad-argument-message)
;=> "bad argument"

make-type-name-message

make-type-name-message TYPNAMprocedure

Returns an argument type message for the TYPNAM by supplying an article.

Example:

(make-type-name-message integer) ;=> an integer"
(make-type-name-message "symbol in {foo bar baz}")
;=> "a symbol in {foo bar baz}"

make-error-type-message

make-error-type-message TYPNAM #!optional ARGNAMprocedure

Returns a type error message from the TYPNAM} and optional {{ARGNAM.

Uses make-bad-argument-message and make-type-name-message to build the message components.

Example:

(make-error-type-message 'integer "count")
;=> "bad `count' argument type - not an integer"

signal-type-error

signal-type-error LOC MSG OBJ...procedure

Raises a non-continuable type error - (({exn type)}}.

error-argument-type

error-argument-type LOC OBJ TYPNAM #!optional ARGNAMprocedure

Raises a type-error where is message is constructed from the TYPNAM and ARGNAM.

Uses signal-type-error and make-error-type-message.

warning-argument-type

warning-argument-type LOC OBJ TYPNAM #!optional ARGNAMprocedure

A warning is issued with a message similar to that of error-argument-type.

error-defined-value

error-defined-value LOC OBJ #!optional ARGNAMprocedure

error-bound-value

error-bound-value LOC OBJ #!optional ARGNAMprocedure

error-fixnum

error-fixnum LOC OBJ #!optional ARGNAMprocedure

error-positive-fixnum

error-positive-fixnum LOC OBJ #!optional ARGNAMprocedure

error-natural-fixnum

error-natural-fixnum LOC OBJ #!optional ARGNAMprocedure

error-flonum

error-flonum LOC OBJ #!optional ARGNAMprocedure

error-integer

error-integer LOC OBJ #!optional ARGNAMprocedure

error-positive-integer

error-positive-integer LOC OBJ #!optional ARGNAMprocedure

error-natural-integer

error-natural-integer LOC OBJ #!optional ARGNAMprocedure

error-number

error-number LOC OBJ #!optional ARGNAMprocedure

error-positive-number

error-positive-number LOC OBJ #!optional ARGNAMprocedure

error-natural-number

error-natural-number LOC OBJ #!optional ARGNAMprocedure

error-procedure

error-procedure LOC OBJ #!optional ARGNAMprocedure

error-input-port

error-input-port LOC OBJ #!optional ARGNAMprocedure

error-output-port

error-output-port LOC OBJ #!optional ARGNAMprocedure

error-list

error-list LOC OBJ #!optional ARGNAMprocedure

error-pair

error-pair LOC OBJ #!optional ARGNAMprocedure

error-blob

error-blob LOC OBJ #!optional ARGNAMprocedure

error-vector

error-vector LOC OBJ #!optional ARGNAMprocedure

error-structure

error-structure LOC OBJ TAG #!optional ARGNAMprocedure

error-record and error-record-type are essentially synonyms.

error-symbol

error-symbol LOC OBJ #!optional ARGNAMprocedure

error-keyword

error-keyword LOC OBJ #!optional ARGNAMprocedure

error-string

error-string LOC OBJ #!optional ARGNAMprocedure

error-char

error-char LOC OBJ #!optional ARGNAMprocedure

error-boolean

error-boolean LOC OBJ #!optional ARGNAMprocedure

error-alist

error-alist LOC OBJ #!optional ARGNAMprocedure

error-minimum-argument-count

error-minimum-argument-count LOC ARGC MINARGCprocedure

error-argument-count

error-argument-count LOC ARGC MAXARGCprocedure

error-open-interval

error-open-interval LOC NUM MINNUM MAXNUM #!optional ARGNAMprocedure

error-closed-interval

error-closed-interval LOC NUM MINNUM MAXNUM #!optional ARGNAMprocedure

error-half-open-interval

error-half-open-interval LOC NUM MINNUM MAXNUM #!optional ARGNAMprocedure

error-half-closed-interval

error-half-closed-interval LOC NUM MINNUM MAXNUM #!optional ARGNAMprocedure

error-interval

error-interval LOC NUM LEFT MINNUM MAXNUM RIGHT #!optional ARGNAMprocedure

LEFT is a character, symbol, or string that denotes the symbolic opening of an interval.

RIGHT is a character, symbol, or string that denotes the symbolic closing of an interval.

define-error-type

(define-error-type TYPNAM [TYPMSG])syntax

TYPNAM is a symbol.

TYPMSG is a symbol or string.

Creates a procedure definition for error-TYPNAM} with the signature of the above error procedures. The type-name is either {{TYPMSG, when present, or "TYPNAM".

(define-error-type hash-table)
;=>
;(define (error-hash-table loc obj #!optional argnam)
;  (error-argument-type loc obj "hash-table" argnam) )

(define-error-type byte-order "symbol in {big-endian little-endian}")
;=>
;(define (error-byte-order loc obj #!optional argnam)
;  (error-argument-type loc obj "symbol in {big-endian little-endian}" argnam) )

SRFI 4 Checks

Usage

(require-extension srfi-4-checks)

check-s8vector

check-s8vector LOC OBJ #!optional ARGNAMprocedure

check-u8vector

check-u8vector LOC OBJ #!optional ARGNAMprocedure

check-s16vector

check-s16vector LOC OBJ #!optional ARGNAMprocedure

check-u16vector

check-u16vector LOC OBJ #!optional ARGNAMprocedure

check-s32vector

check-s32vector LOC OBJ #!optional ARGNAMprocedure

check-u32vector

check-u32vector LOC OBJ #!optional ARGNAMprocedure

check-s64vector

check-s64vector LOC OBJ #!optional ARGNAMprocedure

check-u64vector

check-u64vector LOC OBJ #!optional ARGNAMprocedure

check-f32vector

check-f32vector LOC OBJ #!optional ARGNAMprocedure

check-f64vector

check-f64vector LOC OBJ #!optional ARGNAMprocedure

SRFI 4 Errors

Usage

(require-extension srfi-4-errors)

error-s8vector

error-s8vector LOC OBJ #!optional ARGNAMprocedure

error-u8vector

error-u8vector LOC OBJ #!optional ARGNAMprocedure

error-s16vector

error-s16vector LOC OBJ #!optional ARGNAMprocedure

error-u16vector

error-u16vector LOC OBJ #!optional ARGNAMprocedure

error-s32vector

error-s32vector LOC OBJ #!optional ARGNAMprocedure

error-u32vector

error-u32vector LOC OBJ #!optional ARGNAMprocedure

error-s64vector

error-s64vector LOC OBJ #!optional ARGNAMprocedure

error-u64vector

error-u64vector LOC OBJ #!optional ARGNAMprocedure

error-f32vector

error-f32vector LOC OBJ #!optional ARGNAMprocedure

error-f64vector

error-f64vector LOC OBJ #!optional ARGNAMprocedure

Bugs & Limitations

Notes

Author

Kon Lovett

Version history

2.0.0 ; Removed copy of inline-type-checks.scm to (chicken-home). Ticket #1327
1.13.0 ; Added egg module.
1.12.6 ; inline-type-checks.scm copied to Chicken Repository. Produces shared+static object files.
1.12.5 ; define-inline-check-type generates name with "%" prefix.
1.12.4 ; Moved optional argument name checks until after error detected.
1.12.3 ; Fix for error-minimum-argument-coun and error-argument-count.
1.12.2 ; Better no-install support.
1.12.1 ; Deprecated ...-cardinal-... in favor of ...-natural-....
1.12.0 ; Removed error-utils & conditions.
1.11.0 ; Added error-utils.
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-2016 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.

Contents »