Note: This is taken from the Chicken Wiki, where a more recent version could be available.
SRFI-12 condition object api generator.
A condition has a unique name, optional conditions to composite, required and optional properties. The conditions to composite can be viewed as an inheritance hierarchy.
Unlike "pure" SRFI-12 condition parents and property names must be disjoint in the hierachy. This is a major violation of SRFI-12, but follows R6RS requirements.
[syntax] (define-condition CONDITION-NAME [PROPERTY ...]) [syntax] (define-condition (CONDITION-NAME CONDITION-NAME ...) [PROPERTY ...])
A CONDITION-NAME is a symbol. When multiple names are specified the first is the name of the condition, the rest are the names of other conditions to composite.
A PROPERTY is either a PROPERTY-NAME, or a list of the form (PROPERTY-NAME [DEFAULT]). PROPERTY-NAME is a symbol.
When the list form is specified the property is optional, with DEFAULT as the default value, otherwise it is required.
[syntax] (declare-condition CONDITION-NAME)
Constructs a set of procedures for the condition interface CONDITION-NAME.
The condition-interface for CONDITION-NAME and all inherited conditions (see define-condition above) must be available at macro-expansion time. It is recommended that the interfaces be kept in "syntax" source files, and the implementations (this macro) be kept in "executable" source files, which include (or require, require-extension, etc.) the "syntax" file(s).
The names of the procedures are based on either the CONDITION-NAME or the CONDITION-BASENAME. The CONDITION-BASENAME is CONDITION-NAME, except for any leading & (ampersand) character. So, if '&file-error' is a condition-name, then 'file-error' is the condition-basename.
- Condition Procedures
[procedure] (CONDITION-BASENAME? OBJECT)
Is the OBJECT an instance of the condition for CONDITION-NAME?
[procedure] (CONDITION-NAME REQUIRED-PROPERTY-NAME ... #!key KEYWORD-PROPERTY ...)
Returns an instance of the condition for CONDITION-NAME. Those properties designated as optional in the condition-interface definition for CONDITION-NAME, and the condition-interface definitions of any composites, become the KEYWORD-PROPERTY ... sequence. The REQUIRED-PROPERTY-NAME ... sequence is in left-to-right order, corresponding to the order in the original condition-interface definitions, with the most distant ancestor first.
[procedure] (CONDITION-BASENAME-PROPERTY-NAME CONDITION [DEFAULT])
Returns the property value of PROPERTY-NAME for the CONDITION. One such procedure for every property of the condition.
- Property-Condition Procedures
A set of property-condition oriented procedures is created. Use of these is specialized and not recommended.
[procedure] (CONDITION-BASENAME-condition? OBJECT)
Is the OBJECT an instance of the property condition for CONDITION-NAME?
[procedure] (CONDITION-BASENAME-condition PROPERTY-NAME ...)
Returns an instance of the property condition for CONDITION-NAME. The property value arguments are missing when there are no properties for CONDITION-NAME.
[procedure] (CONDITION-BASENAME-condition-ref CONDITION PROPERTY-NAME [DEFAULT])
Returns the value of the property-key PROPERTY-NAME for the CONDITION.
- example-conditions.scm (requires-at-runtime example-conditions-support)
(define-condition &exn location message (arguments)) (define-condition &i/o) (define-condition &file) (define-condition (&file-error &exn &i/o &file) (pathname "unknown")) (define-condition (&file-unreachable-error &file-error) operator)
(include "example-conditions") (declare-condition &exn) (declare-condition &i/o) (declare-condition &file) (declare-condition &file-error) (declare-condition &file-unreachable-error)
(use example-conditions) ; Note below that 'arguments' and pathname are keyword parameters since in the interface ; definitions above they were designated as optional. The required parameters ; location, message, and operator are in a left-to-right order per the interface ; definitions. (signal (&file-unreachable-error 'example "example" 'example-operation #:pathname "foo.bar")) ; signaled condition is composed of: ; exn location='example message="example" arguments= ; i/o ; file ; file-error pathname="foo.bar" ; file-unreachable-error operator='example-operation (define-condition (&file-unreachable-error-foo &file-unreachable-error) bar) (declare-condition &file-unreachable-error-foo) (signal (&file-unreachable-error-foo 'example "example" 'example-operation "bar")) ; signaled condition is composed of: ; exn location='example message="example" arguments= ; i/o ; file ; file-error pathname="unknown" ; file-unreachable-error operator='example-operation ; file-unreachable-error-foo bar="bar" (define-condition (&bad &bad)) (declare-condition &bad) ; Will fail during expansion (define-condition &bad1) (define-condition (&bad2 &bad1)) (define-condition (&bad3 &bad2 &bad1)) (declare-condition &bad3) ; Will fail during expansion
No support for hygienic macros.
Copyright © 2007 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.