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

check-errors

Argument checks, errors & conditions.

  1. check-errors
  2. Documentation
    1. Arugment Conventions
    2. Type Checks
      1. Usage
      2. check-defined-value
      3. check-fixnum
      4. check-positive-fixnum
      5. check-cardinal-fixnum
      6. check-flonum
      7. check-integer
      8. check-positive-integer
      9. check-cardinal-integer
      10. check-number
      11. check-positive-number
      12. check-cardinal-number
      13. check-procedure
      14. check-input-port
      15. check-output-port
      16. check-list
      17. check-pair
      18. check-blob
      19. check-vector
      20. check-structure
      21. check-symbol
      22. check-keyword
      23. check-string
      24. check-char
      25. check-boolean
      26. check-alist
      27. check-minimum-argument-count
      28. check-argument-count
      29. check-open-interval
      30. check-closed-interval
      31. check-half-open-interval
      32. check-half-closed-interval
      33. define-check-type
      34. define-check+error-type
    3. Type Errors
      1. Argument Conventions
      2. Usage
      3. make-bad-argument-message
      4. make-type-name-message
      5. make-error-type-message
      6. signal-type-error
      7. error-argument-type
      8. warning-argument-type
      9. error-defined-value
      10. error-fixnum
      11. error-positive-fixnum
      12. error-cardinal-fixnum
      13. error-flonum
      14. error-integer
      15. error-positive-integer
      16. error-cardinal-integer
      17. error-number
      18. error-positive-number
      19. error-cardinal-number
      20. error-procedure
      21. error-input-port
      22. error-output-port
      23. error-list
      24. error-pair
      25. error-blob
      26. error-vector
      27. error-structure
      28. error-symbol
      29. error-keyword
      30. error-string
      31. error-char
      32. error-boolean
      33. error-alist
      34. error-minimum-argument-count
      35. error-argument-count
      36. error-open-interval
      37. error-closed-interval
      38. error-half-open-interval
      39. error-half-closed-interval
      40. error-interval
      41. define-error-type
    4. Conditions
      1. Argument Conventions
      2. Usage
      3. make-exn-condition
      4. make-exn-condition+
      5. make-condition+
      6. condition-predicate*
      7. make-condition-predicate
      8. condition-property-accessor*
      9. make-condition-property-accessor
    5. SRFI 4 Checks
      1. Usage
      2. check-s8vector
      3. check-u8vector
      4. check-s16vector
      5. check-u16vector
      6. check-s32vector
      7. check-u32vector
      8. check-f32vector
      9. check-f64vector
    6. SRFI 4 Errors
      1. Usage
      2. error-s8vector
      3. error-u8vector
      4. error-s16vector
      5. error-u16vector
      6. error-s32vector
      7. error-u32vector
      8. error-f32vector
      9. error-f64vector
  3. Notes
  4. Author
  5. Version history
  6. License

Documentation

Arugment 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 arugments, 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

[procedure] (check-defined-value LOC OBJ [ARGNAM]) => *

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

check-fixnum

[procedure] (check-fixnum LOC OBJ [ARGNAM]) => *

check-positive-fixnum

[procedure] (check-positive-fixnum LOC OBJ [ARGNAM]) => *

check-cardinal-fixnum

[procedure] (check-cardinal-fixnum LOC OBJ [ARGNAM]) => *

check-flonum

[procedure] (check-flonum LOC OBJ [ARGNAM]) => *

check-integer

[procedure] (check-integer LOC OBJ [ARGNAM]) => *

check-positive-integer

[procedure] (check-positive-integer LOC OBJ [ARGNAM]) => *

check-cardinal-integer

[procedure] (check-cardinal-integer LOC OBJ [ARGNAM]) => *

check-number

[procedure] (check-number LOC OBJ [ARGNAM]) => *

check-positive-number

[procedure] (check-positive-number LOC OBJ [ARGNAM]) => *

check-cardinal-number

[procedure] (check-cardinal-number LOC OBJ [ARGNAM]) => *

check-procedure

[procedure] (check-procedure LOC OBJ [ARGNAM]) => *

check-input-port

[procedure] (check-input-port LOC OBJ [ARGNAM]) => *

check-output-port

[procedure] (check-output-port LOC OBJ [ARGNAM]) => *

check-list

[procedure] (check-list LOC OBJ [ARGNAM]) => *

check-pair

[procedure] (check-pair LOC OBJ [ARGNAM]) => *

check-blob

[procedure] (check-blob LOC OBJ [ARGNAM]) => *

check-vector

[procedure] (check-vector LOC OBJ [ARGNAM]) => *

check-structure

[procedure] (check-structure LOC OBJ TAG [ARGNAM]) => *
[procedure] (check-record LOC OBJ TAG [ARGNAM]) => *
[procedure] (check-record-type LOC OBJ TAG [ARGNAM]) => *

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

check-symbol

[procedure] (check-symbol LOC OBJ [ARGNAM]) => *

check-keyword

[procedure] (check-keyword LOC OBJ [ARGNAM]) => *

check-string

[procedure] (check-string LOC OBJ [ARGNAM]) => *

check-char

[procedure] (check-char LOC OBJ [ARGNAM]) => *

check-boolean

[procedure] (check-boolean LOC OBJ [ARGNAM]) => *

check-alist

[procedure] (check-alist LOC OBJ [ARGNAM]) => *

check-minimum-argument-count

[procedure] (check-minimum-argument-count LOC ARGC MINARGC) => *

check-argument-count

[procedure] (check-argument-count LOC ARGC MAXARGC) => *

check-open-interval

[procedure] (check-open-interval LOC NUM MINNUM MAXNUM [ARGNAM]) => *

NUM in ]MINNUM MAXNUM[.

check-closed-interval

[procedure] (check-closed-interval LOC NUM MINNUM MAXNUM [ARGNAM]) => *

NUM in [MINNUM MAXNUM].

check-half-open-interval

[procedure] (check-half-open-interval LOC NUM MINNUM MAXNUM [ARGNAM]) => *

NUM in ]MINNUM MAXNUM].

check-half-closed-interval

[procedure] (check-half-closed-interval LOC NUM MINNUM MAXNUM [ARGNAM]) => *

NUM in [MINNUM MAXNUM[.

define-check-type

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

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 a {{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

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

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 a {{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

[procedure] (make-bad-argument-message [ARGNAM]) => string

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

[procedure] (make-type-name-message TYPNAM) => string

Returns an argument type message for the TYPNAM.

Example:

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

Note that make-type-name-message is suitable only for English. It supplies a suitable article for the type-name.

make-error-type-message

[procedure] (make-error-type-message TYPNAM [ARGNAM]) => string

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

[procedure] (signal-type-error LOC MSG OBJ...)

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

error-argument-type

[procedure] (error-argument-type LOC OBJ TYPNAM [ARGNAM])

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

[procedure] (warning-argument-type LOC OBJ TYPNAM [ARGNAM])

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

error-defined-value

[procedure] (error-defined-value LOC OBJ [ARGNAM])

error-fixnum

[procedure] (error-fixnum LOC OBJ [ARGNAM])

error-positive-fixnum

[procedure] (error-positive-fixnum LOC OBJ [ARGNAM])

error-cardinal-fixnum

[procedure] (error-cardinal-fixnum LOC OBJ [ARGNAM])

error-flonum

[procedure] (error-flonum LOC OBJ [ARGNAM])

error-integer

[procedure] (error-integer LOC OBJ [ARGNAM])

error-positive-integer

[procedure] (error-positive-integer LOC OBJ [ARGNAM])

error-cardinal-integer

[procedure] (error-cardinal-integer LOC OBJ [ARGNAM])

error-number

[procedure] (error-number LOC OBJ [ARGNAM])

error-positive-number

[procedure] (error-positive-number LOC OBJ [ARGNAM])

error-cardinal-number

[procedure] (error-cardinal-number LOC OBJ [ARGNAM])

error-procedure

[procedure] (error-procedure LOC OBJ [ARGNAM])

error-input-port

[procedure] (error-input-port LOC OBJ [ARGNAM])

error-output-port

[procedure] (error-output-port LOC OBJ [ARGNAM])

error-list

[procedure] (error-list LOC OBJ [ARGNAM])

error-pair

[procedure] (error-pair LOC OBJ [ARGNAM])

error-blob

[procedure] (error-blob LOC OBJ [ARGNAM])

error-vector

[procedure] (error-vector LOC OBJ [ARGNAM])

error-structure

[procedure] (error-structure LOC OBJ TAG [ARGNAM])

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

error-symbol

[procedure] (error-symbol LOC OBJ [ARGNAM])

error-keyword

[procedure] (error-keyword LOC OBJ [ARGNAM])

error-string

[procedure] (error-string LOC OBJ [ARGNAM])

error-char

[procedure] (error-char LOC OBJ [ARGNAM])

error-boolean

[procedure] (error-boolean LOC OBJ [ARGNAM])

error-alist

[procedure] (error-alist LOC OBJ [ARGNAM])

error-minimum-argument-count

[procedure] (error-minimum-argument-count LOC ARGC MINARGC)

error-argument-count

[procedure] (error-argument-count LOC ARGC MAXARGC)

error-open-interval

[procedure] (error-open-interval LOC NUM MINNUM MAXNUM [ARGNAM])

error-closed-interval

[procedure] (error-closed-interval LOC NUM MINNUM MAXNUM [ARGNAM])

error-half-open-interval

[procedure] (error-half-open-interval LOC NUM MINNUM MAXNUM [ARGNAM])

error-half-closed-interval

[procedure] (error-half-closed-interval LOC NUM MINNUM MAXNUM [ARGNAM])

error-interval

[procedure] (error-interval LOC NUM LEFT MINNUM MAXNUM RIGHT [ARGNAM])

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

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

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

Conditions

Argument Conventions

MSG is a string, or #f.

ARGS is a list, or #f.

COND is a:

property-condition
literal
symbol
(make-property-condition <symbol>)
list
(apply make-property-condition <list>)

KIND is a symbol.

PROP is a symbol.

Usage

(require-extension conditions)

make-exn-condition

[procedure] (make-exn-condition LOC MSG ARGS) => property-condition

Returns an exn property-condition with optional location, message and arguments properties.

make-exn-condition+

[procedure] (make-exn-condition+ LOC MSG ARGS [COND...]) => property-condition

Returns a composite-condition exn COND....

make-condition+

[procedure] (make-condition+ COND...) => property-condition

Returns a composite-condition COND....

condition-predicate*

[procedure] (condition-predicate* KIND) => (procedure (*) boolean)

Returns a "memioized" condition-predicate for KIND.

make-condition-predicate

[syntax] (make-condition-predicate KIND...) => (procedure (*) boolean)

Returns a condition-predicate for KIND....

condition-property-accessor*

[procedure] (condition-property-accessor* KIND PROP [DEFAULT]) => (procedure (*) boolean)

Returns a "memioized" condition-property-accessor for KIND.

make-condition-property-accessor

[syntax] (make-condition-property-accessor KIND PROP [DEFAULT]) => (procedure (*) boolean)

Returns a condition-property-accessor for KIND PROP.

SRFI 4 Checks

Usage

(require-extension srfi-4-checks)

check-s8vector

[procedure] (check-s8vector LOC OBJ [ARGNAM]) => *

check-u8vector

[procedure] (check-u8vector LOC OBJ [ARGNAM]) => *

check-s16vector

[procedure] (check-s16vector LOC OBJ [ARGNAM]) => *

check-u16vector

[procedure] (check-u16vector LOC OBJ [ARGNAM]) => *

check-s32vector

[procedure] (check-s32vector LOC OBJ [ARGNAM]) => *

check-u32vector

[procedure] (check-u32vector LOC OBJ [ARGNAM]) => *

check-f32vector

[procedure] (check-f32vector LOC OBJ [ARGNAM]) => *

check-f64vector

[procedure] (check-f64vector LOC OBJ [ARGNAM]) => *

SRFI 4 Errors

Usage

(require-extension srfi-4-errors)

error-s8vector

[procedure] (error-s8vector LOC OBJ [ARGNAM])

error-u8vector

[procedure] (error-u8vector LOC OBJ [ARGNAM])

error-s16vector

[procedure] (error-s16vector LOC OBJ [ARGNAM])

error-u16vector

[procedure] (error-u16vector LOC OBJ [ARGNAM])

error-s32vector

[procedure] (error-s32vector LOC OBJ [ARGNAM])

error-u32vector

[procedure] (error-u32vector LOC OBJ [ARGNAM])

error-f32vector

[procedure] (error-f32vector LOC OBJ [ARGNAM])

error-f64vector

[procedure] (error-f64vector LOC OBJ [ARGNAM])

Notes

Author

kon lovett

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.