You are looking at historical revision 15710 of this page. It may differ significantly from its current revision.

check-errors

Argument checks, errors & conditions.

Documentation

Conditions

(require-extension conditions)

make-exn-condition

[procedure] (make-exn-condition LOCATION MESSAGE ARGUMENTS) => PROPERTY-CONDITION

LOCATION 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-CONDITION

LOCATION, 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-CONDITION

CONDITION as make-exn-condition+

Returns a composite-condition CONDITION....

condition-predicate*

[procedure] (condition-predicate* KIND) => PROCEDURE/1

Returns a "memioized" condition-predicate for KIND.

KIND is a symbol.

make-condition-predicate

[syntax] (make-condition-predicate KIND...) => PROCEDURE/1

Returns a condition-predicate for KIND....

KIND is a symbol.

condition-property-accessor*

[procedure] (condition-property-accessor* KIND PROP [DEFAULT]) => PROCEDURE/1

Returns 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/1

Returns a condition-property-accessor for KIND PROP.

KIND and PROP are symbol.

Type Errors

(require-extension type-errors)

make-error-type-message

[procedure] (make-error-type-message TYPE-NAME [ARGUMENT-NAME]) => STRING

TYPE-NAME is a symbol or string. ARGUMENT-NAME is a 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"

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 TYPE-NAME [ARGUMENT-NAME])

error-positive-fixnum

[procedure] (error-positive-fixnum LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-cardinal-fixnum

[procedure] (error-cardinal-fixnum LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-flonum

[procedure] (error-flonum LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-integer

[procedure] (error-integer LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-positive-integer

[procedure] (error-positive-integer LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-cardinal-integer

[procedure] (error-cardinal-integer LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-number

[procedure] (error-number LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-positive-number

[procedure] (error-positive-number LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-cardinal-number

[procedure] (error-cardinal-number LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-procedure

[procedure] (error-procedure LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-input-port

[procedure] (error-input-port LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-output-port

[procedure] (error-output-port LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-list

[procedure] (error-list LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-pair

[procedure] (error-pair LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-blob

[procedure] (error-blob LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-vector

[procedure] (error-vector LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-structure

[procedure] (error-structure LOCATION OBJECT TAG [ARGUMENT-NAME])

error-symbol

[procedure] (error-symbol LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-keyword

[procedure] (error-keyword LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-string

[procedure] (error-string LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-char

[procedure] (error-char LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

error-boolean

[procedure] (error-boolean LOCATION OBJECT TYPE-NAME [ARGUMENT-NAME])

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) )

Type Checks

(require-extension type-checks)

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

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-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])

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) ) )

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 (check-hash-table loc obj #!optional argnam)
;     (unless (hash-table? obj)
;       (error-hash-table loc obj argnam) ) )

Usage

Examples

Notes

Requirements

Bugs and Limitations

Author

kon lovett

Version history

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.