source: project/wiki/eggref/5/coops-utils @ 36238

Last change on this file since 36238 was 36238, checked in by kon, 9 months ago

import now

File size: 8.1 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(import 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(import 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==== describe-object-slot
82
83<procedure>(describe-object-slot INSTANCE SLOT [NAME-MAXLEN 32 [OUT (current-output-port)]])</procedure>
84
85Prints information about the {{INSTANCE}}'s {{SLOT}} to the {{output-port}}
86{{OUT}}. Does not append a {{(newline)}}.
87
88{{NAME-MAXLEN}} is the maximum number of single-width characters in a slotname.
89
90
91=== Introspection
92
93Some [[TInyCLOS]] inspired property readers.
94
95==== Argument Conventions
96
97Provides predicates and read accessors for {{coops objects}}.
98
99{{OBJECT}} is a Scheme {{object}}.
100
101{{CLASS}} is a coops {{class}}.
102
103{{GENERIC}} is a coops {{generic-procedure}}.
104
105{{METHOD}} is a coops {{generic-procedure}} {{method}}.
106Do not apply any but the supplied API to instances of this type!
107
108==== Usage
109
110<enscript language=scheme>
111(import coops-introspection)
112</enscript>
113
114==== instance-of?
115
116<procedure>(instance-of? OBJECT CLASS) --> boolean</procedure>
117
118Is {{OBJECT}} an {{instance}} of the {{CLASS>}}?
119
120==== class?
121
122<procedure>(class? OBJECT) --> boolean</procedure>
123
124Is {{OBJECT}} an {{instance}} of the {{<standard-class>}}?
125
126<procedure>(check-class LOC OBJ [ARGNAM]) --> *</procedure>
127<procedure>(error-class LOC OBJ [ARGNAM])</procedure>
128
129==== instance?
130
131<procedure>(instance? OBJECT) --> boolean</procedure>
132
133Is {{OBJECT}} an instance of a basic class. Neither an {{instance}} of
134the {{<standard-class>}} or a primitive such as {{boolean}} or {{vector}}?
135
136<procedure>(check-instance LOC OBJ [ARGNAM]) --> *</procedure>
137<procedure>(error-instance LOC OBJ [ARGNAM])</procedure>
138
139==== primitive-instance?
140
141<procedure>(primitive-instance? OBJECT) --> boolean</procedure>
142
143Is {{OBJECT}} an {{instance}} of the {{<primitive-object>}} class?
144
145==== generic?
146
147<procedure>(generic? OBJECT) --> boolean</procedure>
148
149Synonym for {{generic-procedure?}}.
150
151<procedure>(check-generic LOC OBJ [ARGNAM]) --> *</procedure>
152<procedure>(error-generic LOC OBJ [ARGNAM])</procedure>
153
154==== method?
155
156<procedure>(method? OBJECT) --> boolean</procedure>
157
158Is {{OBJECT}} a {{method}} of a {{generic-procedure}}?
159
160"Note" that the current implementation of methods does not depend on the type
161system. This function only validates the form of the argument and can be fooled.
162
163<procedure>(check-method LOC OBJ [ARGNAM]) --> *</procedure>
164<procedure>(error-method LOC OBJ [ARGNAM])</procedure>
165
166==== class-precedence-list
167
168<procedure>(class-precedence-list CLASS) --> (list-of class)</procedure>
169
170Returns the superclasses of {{CLASS}}.
171
172==== class-slots
173
174<procedure>(class-slots CLASS) --> (list-of symbol)</procedure>
175
176Returns the slot names of {{CLASS}}.
177
178==== class-direct-supers
179
180<procedure>(class-direct-supers CLASS) --> (list-of class)</procedure>
181
182Returns the uninherited superclasses of {{CLASS}}.
183
184==== class-direct-slots
185
186<procedure>(class-direct-slots CLASS) --> (list-of symbol)</procedure>
187
188Returns the uninherited slot names of {{CLASS}}.
189
190==== generic-anonymous?
191
192<procedure>(generic-anonymous? GENERIC) --> boolean</procedure>
193
194Is {{GENERIC}} an unnamed {{generic-procedure}}.
195
196==== generic-name
197
198<procedure>(generic-name GENERIC) --> (union #f symbol)</procedure>
199
200Returns the name of {{GENERIC}}. The name is {{#f}} for an anonymous generic
201procedure.
202
203==== generic-specialized-arguments
204
205<procedure>(generic-specialized-arguments GENERIC) --> (list-of symbol)</procedure>
206
207The arguments that {{GENERIC}} is specialized upon.
208
209==== generic-primary-methods
210
211<procedure>(generic-primary-methods GENERIC) --> (list-of method)</procedure>
212
213Returns the list of {{#:primary}} methods for {{GENERIC}}.
214
215==== generic-before-methods
216
217<procedure>(generic-before-methods GENERIC) --> (list-of method)</procedure>
218
219Returns the  list of {{#:before}} methods for {{GENERIC}}.
220
221==== generic-after-methods
222
223<procedure>(generic-after-methods GENERIC) --> (list-of method)</procedure>
224
225Returns the list of {{#:after}} methods for {{GENERIC}}.
226
227==== generic-around-methods
228
229<procedure>(generic-around-methods GENERIC) --> (list-of method)</procedure>
230
231Returns the list of {{#:around}} methods for {{GENERIC}}.
232
233==== method-specializers
234
235<procedure>(method-specializers METHOD) --> (list-of class)</procedure>
236
237Returns the classes that specialize {{METHOD}}.
238
239==== method-procedure
240
241<procedure>(method-procedure METHOD) --> procedure</procedure>
242
243Returns the {{procedure}} for {{METHOD}}.
244
245
246== Usage
247
248<enscript language=scheme>
249(import coops-utils)
250</enscript>
251
252
253== Examples
254
255<enscript language=scheme>
256(import coops coops-introspection)
257
258(define (print-methods generic)
259  (for-each
260    (lambda (m)
261      (print
262        (generic-name generic)
263        " specialized by " (method-specializers m)
264        " as " (method-procedure m)))
265    (generic-primary-methods generic)) )
266</enscript>
267
268
269== Requirements
270
271[[srfi 1]]
272[[srfi 13]]
273[[coops]]
274[[type-checks]]
275
276
277== Bugs and Limitations
278
279* The introspection API is brittle, especially the generics portion.
280
281Suggested only for use during ''REPL'' development with [[coops]].
282
283
284== Author
285
286[[/users/kon-lovett|Kon Lovett]]
287
288
289== Version history
290
291; 2.0.0 : CHICKEN 5 release.
292; 1.2.0 : Add {{make-copy}}.
293; 1.1.0 : Collect TinyCLOS synonyms in own module: {{coops-introspection-tinyclos}}; reexport by {{coops-utils}} DEPRECATED.
294; 1.0.4 : Remove test, remove inlines.
295; 1.0.3 : Add test, fix library requirement.
296; 1.0.2 : Fix {{make/copy}} for objects with uninitialized slots, thanks to Sandra Snan
297; 1.0.1 : Fix {{class-direct-supers}} and {{class-direct-slots}}, minor internal optimization.
298; 1.0.0 : Release for coops 1.92
299; 0.0.3 : * UNMAINTAINED *
300; 0.0.2 :
301; 0.0.1 :
302
303
304== License
305
306Copyright (C) 2010-2017 Kon Lovett. All rights reserved.
307
308Permission is hereby granted, free of charge, to any person obtaining a
309copy of this software and associated documentation files (the Software),
310to deal in the Software without restriction, including without limitation
311the rights to use, copy, modify, merge, publish, distribute, sublicense,
312and/or sell copies of the Software, and to permit persons to whom the
313Software is furnished to do so, subject to the following conditions:
314
315The above copyright notice and this permission notice shall be included
316in all copies or substantial portions of the Software.
317
318THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
319IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
320FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
321THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
322OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
323ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
324OTHER DEALINGS IN THE SOFTWARE.
Note: See TracBrowser for help on using the repository browser.