source: project/wiki/eggref/4/fast-generic @ 21109

Last change on this file since 21109 was 21109, checked in by felix winkelmann, 11 years ago

phew

File size: 3.8 KB
Line 
1[[toc:]]
2[[tags: egg]]
3
4
5=== Introduction
6
7Very efficient generic functions over arbitrary types.
8
9
10=== Documentation
11
12==== define-generic
13
14<syntax>(define-generic (NAME ARGUMENT ...) BODY ...)</syntax>
15
16Defines a generic function with the given name, specialized to
17argument-types as described by {{ARGUMENT ...}}. {{ARGUMENT}} should
18be either a symbol or a list of the form {{(TYPE SYMBOL)}} where a
19symbol is equivalent to {{(any SYMBOL)}}.
20
21Calls to {{NAME}} textually following this generic definition will
22be dispatched to the first registered generic with this name that
23matches the types of the arguments given in the procedure call.
24
25==== define-type
26
27<syntax>(define-type TYPENAME PREDICATE [BASETYPE])</syntax>
28
29Defines a named type for objects that satisfy {{PREDICATE}} (a procedure
30of one argument that returns either true or false). If {{BASETYPE}} is given,
31it designates the parent type of {{TYPENAME}}. Thus types may form
32a hierarchy. If {{BASETYPE}} is not given, {{any}} is assumed.
33
34The predicate should be referentially transparent and not cause any side-
35effects.
36
37==== any
38
39  [type] any
40
41The universal base type for objects that satisfy {{any?}}, that is,
42all objects.
43
44
45=== Restrictions
46
47* 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).
48
49* 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.
50
51* Generic functions may not return multiple values and do not accept optional, keyword or rest-arguments.
52
53* 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.
54
55
56=== More information
57
58The author of the original implementation describes the implementation of
59an older version of this code in a paper that can be found
60[[http://chicken.kitten-technologies.co.uk/svn/release/4/fast-generic/doc/p45-tessman.pdf|here]].
61
62
63=== Author
64
65Thant Tessman, ported to CHICKEN by [[/users/felix winkelmann|felix]]
66
67
68=== License
69
70 Copyright (c) Thant Tessman
71 All rights reserved.
72
73 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
74 conditions are met:
75
76   Redistributions of source code must retain the above copyright notice, this list of conditions and the following
77     disclaimer.
78   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
79     disclaimer in the documentation and/or other materials provided with the distribution.
80   Neither the name of the author nor the names of its contributors may be used to endorse or promote
81     products derived from this software without specific prior written permission.
82
83 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
84 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
85 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
86 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
87 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
88 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
89 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
90 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
91 POSSIBILITY OF SUCH DAMAGE.
92
93=== Version History
94
95; 0.3 : slight dispatch optimization; basetype argument to {{define-type}} wasnÄt quoted
96; 0.1 : initial release
97
Note: See TracBrowser for help on using the repository browser.