chickadee » procedure-decoration

procedure-decoration

Introduction

Chicken Scheme procedures have attributes, aspects of the procedure object that can be operated upon. Such an attribute is known as a "procedure decoration".

This extension provides a facility to perform procedure decoration operations.

Documentation

An interface for procedure decoration. Similar to the lolevel unit extend-procedure interface but allowing many decorations, not just one.

A PREDICATE is a procedure of one argument, a procedure decoration. The predicate must return a truth value indicating whether the argument is a decoration of the proper kind.

A DECORATOR is a procedure of at least one argument, the current procedure decoration, which is (void) initially. The decorator must return an object to replace the current decoration.

Procedure Decorator

A more sophisticated interface for procedure decoration.

make-procedure-decorator

(make-procedure-decorator PREDICATE DECORATOR RETRIEVER [#:initializer INITIALIZER] [#:replace? REPLACE?]) procedure

Returns a new procedure-decorator.

The RETRIEVER is a procedure of at least one argument, the current procedure decoration, returning the procedure decoration object. Any following arguments are from the procedure-decoration call that will invoke the RETRIEVER.

The INITIALIZER is a procedure of varying arity, returning the procedure decoration initial object. The arguments are from the decorate-procedure call that invokes the INITIALIZER. The INITIALIZER is invoked only once per procedure to decorate.

The default INITIALIZER is built from the DECORATOR. The DECORATOR will be called with a first argument of (void), and any other arguments from the decorate-procedure call.

The REPLACE? flag determines whether the procedure object of a decorated procedure will be replaced (become). The default is #f.

procedure-decorator?

(procedure-decorator? OBJECT) procedure

Is the OBJECT a procedure-decorator?

decorate-procedure

(decorate-procedure PROCEDURE PROCEDURE-DECORATOR [ARGUMENTS ...]) procedure

Decorate the PROCEDURE with the PROCEDURE-DECORATOR.

The PROCEDURE-DECORATOR INITIALIZER is called on the first invocation for PROCEDURE and the DECORATOR on all subsequent invocations.

The optional ARGUMENTS are passed to the invoked PROCEDURE-DECORATOR constructor, as above.

On the first invocation a GC will be performed.

Returns the decorated procedure.

decorated-procedure?

(decorated-procedure? PROCEDURE PROCEDURE-DECORATOR) procedure

Is the PROCEDURE a decorated by PROCEDURE-DECORATOR?

procedure-decoration

(procedure-decoration PROCEDURE PROCEDURE-DECORATOR [ARGUMENTS ...]) procedure

Returns the procedure decoration of PROCEDURE-DECORATOR for the PROCEDURE.

The optional ARGUMENTS are passed to the PROCEDURE-DECORATOR RETRIEVER.

procedure-decorator-getter-and-setter

(procedure-decorator-getter-and-setter PROCEDURE-DECORATOR) procedure

Returns a single argument getter, and creates a two argument setter, for the PROCEDURE-DECORATOR.

The getter takes a PROCEDURE argument. The setter takes PROCEDURE and OBJECT arguments.

Procedure Extender

Not to be confused with the lolevel unit extend-procedure interface.

make-procedure-extender

(make-procedure-extender TAG) procedure

Returns a simple PROCEDURE-DECORATOR that recognizes its' decorations by the TAG and accepts any object as a decoration.

The TAG is any object suitable for testing with eq?.

define-procedure-extender

(define-procedure-extender TAG [GETTER-NAME [PREDICATE-NAME]]) syntax

Creates a functional interface for a PROCEDURE-DECORATOR that uses the {{TAG} symbol.

Defines the PROCEDURE-DECORATOR as TAG-decorator.

Defines a procedure named GETTER-NAME that takes one argument, a decorated procedure, and returns the procedure decoration. Creates a corresponding setter. The default GETTER-NAME is TAG-decoration.

Defines a procedure named PREDICATE-NAME that takes one argument, a procedure, and returns whether the procedure is decorated. The default PREDICATE-NAME is TAG-decorated?.

Lambda Decoration Interface

A lower level interface for procedure decoration.

decorated-lambda?

(decorated-lambda? PROCEDURE PREDICATE) procedure

Is the PROCEDURE decorated per the PREDICATE?

lambda-decoration

(lambda-decoration PROCEDURE PREDICATE) procedure

Returns an object per the PREDICATE or #f.

decorate-lambda

(decorate-lambda PROCEDURE PREDICATE DECORATOR) procedure

Decorate the PROCEDURE per the PREDICATE with the result of the DECORATOR.

Returns the decorated procedure.

Usage

(require-extension procedure-decoration)

Examples

Notes

Author

Kon Lovett

Requirements

check-errors

Version history

2.0.2
Fix for ticket #630.
2.0.1
2.0.0
Initial Chicken 4 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.

Contents »