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

Last change on this file since 26117 was 26117, checked in by sjamaan, 9 years ago

Fix fast-generic page title

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