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

check-errors

Argument checks, errors & conditions.

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

Documentation

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

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

Type Errors

(require-extension type-errors)

make-error-type-message

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

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

(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.

SRFI 4 Checks

(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

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

Usage

Examples

Notes

Requirements

Bugs and Limitations

Author

kon lovett

Version history

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.