You are looking at historical revision 19116 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. 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
    2. Type Errors
      1. Usage
      2. make-error-type-message
      3. signal-type-error
      4. error-argument-type
      5. warning-argument-type
      6. error-defined-value
      7. error-fixnum
      8. error-positive-fixnum
      9. error-cardinal-fixnum
      10. error-flonum
      11. error-integer
      12. error-positive-integer
      13. error-cardinal-integer
      14. error-number
      15. error-positive-number
      16. error-cardinal-number
      17. error-procedure
      18. error-input-port
      19. error-output-port
      20. error-list
      21. error-pair
      22. error-blob
      23. error-vector
      24. error-structure
      25. error-symbol
      26. error-keyword
      27. error-string
      28. error-char
      29. error-boolean
      30. error-alist
      31. error-minimum-argument-count
      32. error-argument-count
      33. error-open-interval
      34. error-closed-interval
      35. error-half-open-interval
      36. error-half-closed-interval
      37. define-error-type
    3. Conditions
      1. Usage
      2. make-exn-condition
      3. make-exn-condition+
      4. make-condition+
      5. condition-predicate*
      6. make-condition-predicate
      7. condition-property-accessor*
      8. make-condition-property-accessor
    4. 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
    5. 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

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-defined-value

[procedure] (check-defined-value LOCATION OBJECT [ARGUMENT-NAME])

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

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]) => 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-defined-value

[procedure] (error-defined-value LOCATION OBJECT [ARGUMENT-NAME])

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

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

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.