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

Last change on this file since 31342 was 31342, checked in by Kon Lovett, 7 years ago

it is obviously maintained

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