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

Outdated egg!

This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for the CHICKEN 4 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

defun-cond

Introduction

SRFI-12 condition object api generator.

Usage

(require-extension defun-cond)

Documentation

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.

define-condition

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

declare-condition

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

Examples

; Note - this is not a recommeded condition hierarchy

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

- example-conditions-support.scm

(include "example-conditions") (declare-condition &exn) (declare-condition &i/o) (declare-condition &file) (declare-condition &file-error) (declare-condition &file-unreachable-error)

- example.scm

(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

Notes

Bugs and Limitations

No support for hygienic macros.

Author

Kon Lovett

License

Copyright (c) 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.

Requirements

SRFI-12

Version history

1.000
Tentative release