Outdated egg!
This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 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.
TOC »
fast-generic
Introduction
Very efficient generic functions over arbitrary types.
Documentation
define-generic
- (define-generic (NAME ARGUMENT ...) BODY ...)syntax
Defines a generic function with the given name, specialized to argument-types as described by ARGUMENT .... ARGUMENT should be either a symbol or a list of the form (TYPE SYMBOL) where a symbol is equivalent to (any SYMBOL).
Calls to NAME textually following this generic definition will be dispatched to the first registered generic with this name that matches the types of the arguments given in the procedure call.
define-type
- (define-type TYPENAME PREDICATE [BASETYPE])syntax
Defines a named type for objects that satisfy PREDICATE (a procedure of one argument that returns either true or false). If BASETYPE is given, it designates the parent type of TYPENAME. Thus types may form a hierarchy. If BASETYPE is not given, any is assumed.
The predicate should be referentially transparent and not cause any side- effects.
any
[type] any
The universal base type for objects that satisfy any?, that is, all objects.
Restrictions
- Generic functions can be exported but type-information and -specialization is not visible outside of the current compilation unit or module (if inside a module).
- Calls to generic functions dispatch according to the generic definitions that occur textually before the call, so it is advisable to define all specializations of generic functions first before defining code that calls them.
- Generic functions may not return multiple values and do not accept optional, keyword or rest-arguments.
- All type-dispatching is done at the call-site of a generic function, which provides many opportunities for the compiler to optimize, but may lead to code-bloat if generic functions with long argument lists are used heavily.
More information
The author of the original implementation describes the implementation of an older version of this code in a paper that can be found here.
Some examples of using this egg can be found in The Chicken Gazette, Issue 14.
Author
Thant Tessman, ported to CHICKEN by felix
License
Copyright (c) Thant Tessman All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Version History
- 0.4
- fixed broken result check and testcases
- 0.3
- slight dispatch optimization; basetype argument to define-type wasn�t quoted
- 0.1
- initial release