You are looking at historical revision 19882 of this page. It may differ significantly from its current revision.
Very efficient generic functions over arbitrary types.
define-generic[syntax] (define-generic (NAME ARGUMENT ...) BODY ...)
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[syntax] (define-type TYPENAME PREDICATE [BASETYPE])
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 universal base type for objects that satisfy any?, that is, all objects.
- 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.
The author of the original implementation describes the implementation of an older version of this code in a paper that can be found here.
Thant Tessman, ported to CHICKEN by felix
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.
- initial release