source: project/wiki/eggref/4/coops-utils @ 27969

Last change on this file since 27969 was 27969, checked in by Kon Lovett, 9 years ago

Rel 1.0.0

File size: 7.4 KB
Line 
1[[tags: egg]]
2
3== coops-utils
4
5* UNMAINTAINED *
6
7[[toc:]]
8
9
10== Documentation
11
12Some [[coops]] stuff.
13
14
15=== Extras
16
17Miscellaneous coops extensions.
18
19==== Argument Conventions
20
21{{INSTANCE}} is a {{coops-instance}}.
22
23{{SLOT}} is a {{symbol}}.
24
25{{INITFORM}} is {{'SLOT OBJECT}}.
26
27==== Usage
28
29<enscript language=scheme>
30(require-extension coops-extras)
31</enscript>
32
33==== slot@
34
35The slot accessor recursion.
36
37<syntax>(slot@ INSTANCE SLOT ...) => *</syntax>
38
39Returns the slot value of the N'th named slot from {{INSTANCE}}.
40
41<syntax>(slot@ INSTANCE SLOT ... [= OBJECT])</syntax>
42
43Sets the slot value of the N'th named slot of {{INSTANCE}} to {{OBJECT}}.
44
45Example:
46
47<enscript language=scheme>
48(use coops coops-extras)
49
50; Needlessly complex for example
51
52(define-class <first> () (next))
53(define-class <second> (<first>) ())
54(define-class <third> (<second>) ())
55
56(define 1st (make <first> 'next (make <second> 'next (make <third> 'next "the end"))))
57
58(slot@ 1st next next next) ;=> "the end"
59
60(slot@ 1st next next next = "still the end")
61(slot@ 1st next next next) ;=> "still the end"
62</enscript>
63
64(From '@' macro by Dan Muresan.)
65
66==== make/copy
67
68<procedure>(make/copy INSTANCE [INITFORM ...]) => coops-instance</procedure>
69
70Returns a copy of the object {{INSTANCE}} except where an {{INITFORM}}
71overrides an existing {{SLOT}} value of the {{INSTANCE}}.
72
73==== describe-object
74
75<procedure>(describe-object INSTANCE [OUT (current-output-port)])</procedure>
76
77Prints information about the {{INSTANCE}} to the {{output-port}} {{OUT}}.
78
79{{describe-object}} is a {{generic-procedure}} specializing the first argument.
80
81A more detailed {{print-object}} for use in a ''REPL''.
82
83
84=== Introspection
85
86Some [[TInyCLOS]] inspired property readers.
87
88==== Argument Conventions
89
90Provides predicates and read accessors for {{coops objects}}.
91
92{{OBJECT}} is a Scheme {{object}}.
93
94{{CLASS}} is a coops {{class}}.
95
96{{GENERIC}} is a coops {{generic-procedure}}.
97
98{{METHOD}} is a coops {{generic-procedure}} {{method}}.
99Do not apply any but the supplied API to instances of this type!
100
101==== Usage
102
103<enscript language=scheme>
104(require-extension coops-introspection)
105</enscript>
106
107==== instance-of?
108
109<procedure>(instance-of? OBJECT CLASS) => boolean</procedure>
110
111Is {{OBJECT}} an {{instance}} of the {{CLASS>}}?
112
113==== class?
114
115<procedure>(class? OBJECT) => boolean</procedure>
116
117Is {{OBJECT}} an {{instance}} of the {{<standard-class>}}?
118
119<procedure>(check-class LOC OBJ [ARGNAM]) => *</procedure>
120<procedure>(error-class LOC OBJ [ARGNAM])</procedure>
121
122==== instance?
123
124<procedure>(instance? OBJECT) => boolean</procedure>
125
126Is {{OBJECT}} not an {{instance}} of the {{<standard-class>}}?
127
128<procedure>(check-instance LOC OBJ [ARGNAM]) => *</procedure>
129<procedure>(error-instance LOC OBJ [ARGNAM])</procedure>
130
131==== primitive-instance?
132
133<procedure>(primitive-instance? OBJECT) => boolean</procedure>
134<procedure>(primitive? OBJECT) => boolean</procedure>
135
136Is {{OBJECT}} an {{instance}} of the {{<primitive-object>}} class?
137
138==== generic?
139
140<procedure>(generic? OBJECT) => boolean</procedure>
141
142Synonym for {{generic-procedure?}}.
143
144<procedure>(check-generic LOC OBJ [ARGNAM]) => *</procedure>
145<procedure>(error-generic LOC OBJ [ARGNAM])</procedure>
146
147==== method?
148
149<procedure>(method? OBJECT) => boolean</procedure>
150
151Is {{OBJECT}} a {{method}} of a {{generic-procedure}}?
152
153<procedure>(check-method LOC OBJ [ARGNAM]) => *</procedure>
154<procedure>(error-method LOC OBJ [ARGNAM])</procedure>
155
156==== class-precedence-list
157
158<procedure>(class-precedence-list CLASS) => (list-of class)</procedure>
159<procedure>(class-cpl CLASS) => (list-of class)</procedure>
160<procedure>(class-supers CLASS) => (list-of class)</procedure>
161
162Returns the superclasses of {{CLASS}}.
163
164==== class-slots
165
166<procedure>(class-slots CLASS) => (list-of symbol)</procedure>
167
168Returns the slot names of {{CLASS}}.
169
170==== class-direct-supers
171
172<procedure>(class-direct-supers CLASS) => (list-of class)</procedure>
173
174Returns the uninherited superclasses of {{CLASS}}.
175
176==== class-direct-slots
177
178<procedure>(class-direct-slots CLASS) => (list-of symbol)</procedure>
179
180Returns the uninherited slot names of {{CLASS}}.
181
182==== generic-anonymous?
183
184<procedure>(generic-anonymous? GENERIC) => boolean</procedure>
185
186Is {{GENERIC}} an unnamed {{generic-procedure}}.
187
188==== generic-name
189
190<procedure>(generic-name GENERIC) => (union #f symbol)</procedure>
191
192Returns the name of {{GENERIC}}. The name is {{#f}} for an anonymous generic
193procedure.
194
195==== generic-specialized-arguments
196
197<procedure>(generic-specialized-arguments GENERIC) => (list-of symbol)</procedure>
198
199The arguments that {{GENERIC}} is specialized upon.
200
201==== generic-primary-methods
202
203<procedure>(generic-primary-methods GENERIC) => (list-of method)</procedure>
204<procedure>(generic-methods GENERIC) => (list-of method)</procedure>
205
206Returns the list of {{primary:}} methods for {{GENERIC}}.
207
208==== generic-before-methods
209
210<procedure>(generic-before-methods GENERIC) => (list-of method)</procedure>
211
212Returns the  list of{{before:}} methods for {{GENERIC}}.
213
214==== generic-after-methods
215
216<procedure>(generic-after-methods GENERIC) => (list-of method)</procedure>
217
218Returns the list of {{after:}} methods for {{GENERIC}}.
219
220==== generic-around-methods
221
222<procedure>(generic-around-methods GENERIC) => (list-of method)</procedure>
223
224Returns the list of {{around:}} methods for {{GENERIC}}.
225
226==== method-specializers
227
228<procedure>(method-specializers METHOD) => (list-of class)</procedure>
229
230Returns the classes that specialize {{METHOD}}.
231
232==== method-procedure
233
234<procedure>(method-procedure METHOD) => procedure</procedure>
235
236Returns the {{procedure}} for {{METHOD}}.
237
238
239== Usage
240
241<enscript language=scheme>
242(require-extension coops-utils)
243</enscript>
244
245
246== Examples
247
248<enscript language=scheme>
249(use coops coops-introspection)
250
251(define (print-methods generic)
252  (for-each
253    (lambda (m)
254      (print
255        (generic-name generic)
256        " specialized by " (method-specializers m)
257        " as " (method-procedure m)))
258    (generic-methods generic)) )
259</enscript>
260
261
262== Notes
263
264* The introspection API is not for use in production code.
265
266While useful it relies on knowledge of the internals of the coops
267implementation and Chicken. It is ''very'' brittle, especially the generics
268portion.
269
270Suggested only for use during ''REPL'' development with [[coops]].
271
272
273== Requirements
274
275[[coops]]
276[[type-checks]]
277
278
279== Bugs and Limitations
280
281
282== Author
283
284[[/users/kon-lovett|Kon Lovett]]
285
286
287== Version history
288
289; 1.0.0 : Release for coops 1.92
290; 0.0.3 : * UNMAINTAINED *
291; 0.0.2 :
292; 0.0.1 :
293
294
295== License
296
297Copyright (C) 2010 Kon Lovett.  All rights reserved.
298
299Permission is hereby granted, free of charge, to any person obtaining a
300copy of this software and associated documentation files (the Software),
301to deal in the Software without restriction, including without limitation
302the rights to use, copy, modify, merge, publish, distribute, sublicense,
303and/or sell copies of the Software, and to permit persons to whom the
304Software is furnished to do so, subject to the following conditions:
305
306The above copyright notice and this permission notice shall be included
307in all copies or substantial portions of the Software.
308
309THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
310IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
311FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
312THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
313OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
314ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
315OTHER DEALINGS IN THE SOFTWARE.
Note: See TracBrowser for help on using the repository browser.