*** empty log message ***
[bpt/guile.git] / doc / goops / goops.texi
CommitLineData
a0e07ba4
NJ
1\input texinfo
2@c -*-texinfo-*-
3@c %**start of header
4@setfilename goops.info
5@settitle Goops Manual
6@set goops
7@setchapternewpage odd
8@paragraphindent 0
9@c %**end of header
10
11@set VERSION 0.3
12
13@dircategory The Algorithmic Language Scheme
14@direntry
15* GOOPS: (goops). The GOOPS reference manual.
16@end direntry
17
18@macro goops
19GOOPS
20@end macro
21
22@macro guile
23Guile
24@end macro
25
26@ifinfo
27This file documents GOOPS, an object oriented extension for Guile.
28
29Copyright (C) 1999, 2000, 2001 Free Software Foundation
30
31Permission is granted to make and distribute verbatim copies of
32this manual provided the copyright notice and this permission notice
33are preserved on all copies.
34
35@end ifinfo
36
37@c This title page illustrates only one of the
38@c two methods of forming a title page.
39
40@titlepage
41@title Goops Manual
42@subtitle For use with GOOPS @value{VERSION}
11ca8865 43@include ../AUTHORS
a0e07ba4
NJ
44
45@c The following two commands
46@c start the copyright page.
47@page
48@vskip 0pt plus 1filll
49Copyright @copyright{} 1999 Free Software Foundation
50
51Permission is granted to make and distribute verbatim copies of
52this manual provided the copyright notice and this permission notice
53are preserved on all copies.
54
55@end titlepage
56
57@node Top, Introduction, (dir), (dir)
58
59@menu
60[When the manual is completed, this will be a flat index in the style of
61 the Emacs manual. More nodes will turn up under parts I-III.]
62
63Part I: Preliminaries
64
65* Introduction::
66* Getting Started::
67
68Part II: Reference Manual
69
70* Reference Manual::
71
72Part III: GOOPS Meta Object Protocol
73
74* MOP Specification::
75
76The GOOPS tutorial
77
78* Tutorial::
79
80* Index::
81* Concept Index::
82* Function and Variable Index::
83@end menu
84
85@iftex
86@chapter Preliminaries
87@end iftex
88
89@node Introduction, Getting Started, Top, Top
90@section Introduction
91
92@goops{} is the object oriented extension to @guile{}. Its
93implementation is derived from @w{STk-3.99.3} by Erick Gallesio and
94version 1.3 of Gregor Kiczales @cite{Tiny-Clos}. It is very close in
95spirit to CLOS, the Common Lisp Object System (@cite{CLtL2}) but is
96adapted for the Scheme language. While GOOPS is not compatible with any
97of these systems, GOOPS contains a compatibility module which allows for
98execution of STKlos programs.
99
100Briefly stated, the @goops{} extension gives the user a full object
101oriented system with multiple inheritance and generic functions with
102multi-method dispatch. Furthermore, the implementation relies on a true
103meta object protocol, in the spirit of the one defined for CLOS
104(@cite{Gregor Kiczales: A Metaobject Protocol}).
105
106@node Getting Started, Reference Manual, Introduction, Top
107@section Getting Started
108
109@menu
110* Running GOOPS::
111
112Examples of some basic GOOPS functionality.
113
114* Methods::
115* User-defined types::
116* Asking for the type of an object::
117
118See further in the GOOPS tutorial available in this distribution in
119info (goops.info) and texinfo format.
120@end menu
121
122@node Running GOOPS, Methods, Getting Started, Getting Started
123@subsection Running GOOPS
124
125@enumerate
126@item
127Type
128
129@smalllisp
130guile-oops
131@end smalllisp
132
133You should now be at the Guile prompt ("guile> ").
134
135@item
136Type
137
138@smalllisp
139(use-modules (oop goops))
140@end smalllisp
141
142to load GOOPS. (If your system supports dynamic loading, you
143should be able to do this not only from `guile-oops' but from an
144arbitrary Guile interpreter.)
145@end enumerate
146
147We're now ready to try some basic GOOPS functionality.
148
149@node Methods, User-defined types, Running GOOPS, Getting Started
150@subsection Methods
151
152@smalllisp
153@group
154(define-method (+ (x <string>) (y <string>))
155 (string-append x y))
156
157(+ 1 2) --> 3
158(+ "abc" "de") --> "abcde"
159@end group
160@end smalllisp
161
162@node User-defined types, Asking for the type of an object, Methods, Getting Started
163@subsection User-defined types
164
165@smalllisp
166(define-class <2D-vector> ()
167 (x #:init-value 0 #:accessor x-component #:init-keyword #:x)
168 (y #:init-value 0 #:accessor y-component #:init-keyword #:y))
169
170@group
171(use-modules (ice-9 format))
172
173(define-method (write (obj <2D-vector>) port)
174 (display (format #f "<~S, ~S>" (x-component obj) (y-component obj))
175 port))
176
177(define v (make <2D-vector> #:x 3 #:y 4))
178
179v --> <3, 4>
180@end group
181
182@group
183(define-method (+ (x <2D-vector>) (y <2D-vector>))
184 (make <2D-vector>
185 #:x (+ (x-component x) (x-component y))
186 #:y (+ (y-component x) (y-component y))))
187
188(+ v v) --> <6, 8>
189@end group
190@end smalllisp
191
192@node Asking for the type of an object, , User-defined types, Getting Started
193@subsection Types
194
195@example
196(class-of v) --> #<<class> <2D-vector> 40241ac0>
197<2D-vector> --> #<<class> <2D-vector> 40241ac0>
198(class-of 1) --> #<<class> <integer> 401b2a98>
199<integer> --> #<<class> <integer> 401b2a98>
200
201(is-a? v <2D-vector>) --> #t
202@end example
203
204@node Reference Manual, MOP Specification, Getting Started, Top
205@chapter Reference Manual
206
207This chapter is the GOOPS reference manual. It aims to describe all the
208syntax, procedures, options and associated concepts that a typical
209application author would need to understand in order to use GOOPS
210effectively in their application. It also describes what is meant by
211the GOOPS ``metaobject protocol'' (aka ``MOP''), and indicates how
212authors can use the metaobject protocol to customize the behaviour of
213GOOPS itself.
214
215For a detailed specification of the GOOPS metaobject protocol, see
216@ref{MOP Specification}.
217
218@menu
219* Introductory Remarks::
220* Defining New Classes::
221* Creating Instances::
222* Accessing Slots::
223* Creating Generic Functions::
224* Adding Methods to Generic Functions::
225* Invoking Generic Functions::
226* Redefining a Class::
227* Changing the Class of an Instance::
228* Introspection::
229* Miscellaneous Functions::
230@end menu
231
232@node Introductory Remarks
233@section Introductory Remarks
234
235GOOPS is an object-oriented programming system based on a ``metaobject
236protocol'' derived from the ones used in CLOS (the Common Lisp Object
237System), tiny-clos (a small Scheme implementation of a subset of CLOS
238functionality) and STKlos.
239
240GOOPS can be used by application authors at a basic level without any
241need to understand what the metaobject protocol (aka ``MOP'') is and how
242it works. On the other hand, the MOP underlies even the customizations
243that application authors are likely to make use of very quickly --- such
244as defining an @code{initialize} method to customize the initialization
245of instances of an application-defined class --- and an understanding of
246the MOP makes it much easier to explain such customizations in a precise
247way. And in the long run, understanding the MOP is the key both to
248understanding GOOPS at a deeper level and to taking full advantage of
249GOOPS' power, by customizing the behaviour of GOOPS itself.
250
251Each of the following sections of the reference manual is arranged
252such that the most basic usage is introduced first, and then subsequent
253subsections discuss the related internal functions and metaobject
254protocols, finishing with a description of how to customize that area of
255functionality.
256
257These introductory remarks continue with a few words about metaobjects
258and the MOP. Readers who do not want to be bothered yet with the MOP
259and customization could safely skip this subsection on a first reading,
260and should correspondingly skip subsequent subsections that are
261concerned with internals and customization.
262
263In general, this reference manual assumes familiarity with standard
264object oriented concepts and terminology. However, some of the terms
265used in GOOPS is less well known, so the Terminology subsection
266provides definitions for these terms.
267
268@menu
269* Metaobjects and the Metaobject Protocol::
270* Terminology::
271@end menu
272
273@node Metaobjects and the Metaobject Protocol
274@subsection Metaobjects and the Metaobject Protocol
275
276The conceptual building blocks of GOOPS are classes, slot definitions,
277instances, generic functions and methods. A class is a grouping of
278inheritance relations and slot definitions. An instance is an object
279with slots that are allocated following the rules implied by its class's
280superclasses and slot definitions. A generic function is a collection
281of methods and rules for determining which of those methods to apply
282when the generic function is invoked. A method is a procedure and a set
283of specializers that specify the type of arguments to which the
284procedure is applicable.
285
286Of these entities, GOOPS represents classes, generic functions and
287methods as ``metaobjects''. In other words, the values in a GOOPS
288program that describe classes, generic functions and methods, are
289themselves instances (or ``objects'') of special GOOPS classes that
290encapsulate the behaviour, respectively, of classes, generic functions,
291and methods.
292
293(The other two entities are slot definitions and instances. Slot
294definitions are not strictly instances, but every slot definition is
295associated with a GOOPS class that specifies the behaviour of the slot
296as regards accessibility and protection from garbage collection.
297Instances are of course objects in the usual sense, and there is no
298benefit from thinking of them as metaobjects.)
299
300The ``metaobject protocol'' (aka ``MOP'') is the specification of the
301generic functions which determine the behaviour of these metaobjects and
302the circumstances in which these generic functions are invoked.
303
304For a concrete example of what this means, consider how GOOPS calculates
305the set of slots for a class that is being defined using
306@code{define-class}. The desired set of slots is the union of the new
307class's direct slots and the slots of all its superclasses. But
308@code{define-class} itself does not perform this calculation. Instead,
309there is a method of the @code{initialize} generic function that is
310specialized for instances of type @code{<class>}, and it is this method
311that performs the slot calculation.
312
313@code{initialize} is a generic function which GOOPS calls whenever a new
314instance is created, immediately after allocating memory for a new
315instance, in order to initialize the new instance's slots. The sequence
316of steps is as follows.
317
318@itemize @bullet
319@item
320@code{define-class} uses @code{make} to make a new instance of the
321@code{<class>}, passing as initialization arguments the superclasses,
322slot definitions and class options that were specified in the
323@code{define-class} form.
324
325@item
326@code{make} allocates memory for the new instance, and then invokes the
327@code{initialize} generic function to initialize the new instance's
328slots.
329
330@item
331The @code{initialize} generic function applies the method that is
332specialized for instances of type @code{<class>}, and this method
333performs the slot calculation.
334@end itemize
335
336In other words, rather than being hardcoded in @code{define-class}, the
337behaviour of class definition is encapsulated by generic function
338methods that are specialized for the class @code{<class>}.
339
340It is possible to create a new class that inherits from @code{<class>},
341which is called a ``metaclass'', and to write a new @code{initialize}
342method that is specialized for instances of the new metaclass. Then, if
343the @code{define-class} form includes a @code{#:metaclass} class option
344whose value is the new metaclass, the class that is defined by the
345@code{define-class} form will be an instance of the new metaclass rather
346than of the default @code{<class>}, and will be defined in accordance
347with the new @code{initialize} method. Thus the default slot
348calculation, as well as any other aspect of the new class's relationship
349with its superclasses, can be modified or overridden.
350
351In a similar way, the behaviour of generic functions can be modified or
352overridden by creating a new class that inherits from the standard
353generic function class @code{<generic>}, writing appropriate methods
354that are specialized to the new class, and creating new generic
355functions that are instances of the new class.
356
357The same is true for method metaobjects. And the same basic mechanism
358allows the application class author to write an @code{initialize} method
359that is specialized to their application class, to initialize instances
360of that class.
361
362Such is the power of the MOP. Note that @code{initialize} is just one
363of a large number of generic functions that can be customized to modify
364the behaviour of application objects and classes and of GOOPS itself.
365Each subsequent section of the reference manual covers a particular area
366of GOOPS functionality, and describes the generic functions that are
367relevant for customization of that area.
368
369We conclude this subsection by emphasizing a point that may seem
370obvious, but contrasts with the corresponding situation in some other
371MOP implementations, such as CLOS. The point is simply that an
372identifier which represents a GOOPS class or generic function is a
373variable with a first-class value, the value being an instance of class
374@code{<class>} or @code{<generic>}. (In CLOS, on the other hand, a
375class identifier is a symbol that indexes the corresponding class
376metaobject in a separate namespace for classes.) This is, of course,
377simply an extension of the tendency in Scheme to avoid the unnecessary
378use of, on the one hand, syntactic forms that require unevaluated
379arguments and, on the other, separate identifier namespaces (e.g. for
380class names), but it is worth noting that GOOPS conforms fully to this
381Schemely principle.
382
383@node Terminology
384@subsection Terminology
385
386It is assumed that the reader is already familiar with standard object
387orientation concepts such as classes, objects/instances,
388inheritance/subclassing, generic functions and methods, encapsulation
389and polymorphism.
390
391This section explains some of the less well known concepts and
392terminology that GOOPS uses, which are assumed by the following sections
393of the reference manual.
394
395@menu
396* Metaclass::
397* Class Precedence List::
398* Accessor::
399@end menu
400
401@node Metaclass
402@subsubsection Metaclass
403
404A @dfn{metaclass} is the class of an object which represents a GOOPS
405class. Put more succinctly, a metaclass is a class's class.
406
407Most GOOPS classes have the metaclass @code{<class>} and, by default,
408any new class that is created using @code{define-class} has the
409metaclass @code{<class>}.
410
411But what does this really mean? To find out, let's look in more detail
412at what happens when a new class is created using @code{define-class}:
413
414@example
415(define-class <my-class> (<object>) . slots)
416@end example
417
418GOOPS actually expands the @code{define-class} form to something like
419this
420
421@example
422(define <my-class> (class (<object>) . slots))
423@end example
424
425and thence to
426
427@example
428(define <my-class>
429 (make <class> #:supers (list <object>) #:slots slots))
430@end example
431
432In other words, the value of @code{<my-class>} is in fact an instance of
433the class @code{<class>} with slot values specifying the superclasses
434and slot definitions for the class @code{<my-class>}. (@code{#:supers}
435and @code{#:slots} are initialization keywords for the @code{dsupers}
436and @code{dslots} slots of the @code{<class>} class.)
437
438In order to take advantage of the full power of the GOOPS metaobject
439protocol (@pxref{MOP Specification}), it is sometimes desirable to
440create a new class with a metaclass other than the default
441@code{<class>}. This is done by writing:
442
443@example
444(define-class <my-class2> (<object>)
445 slot @dots{}
446 #:metaclass <my-metaclass>)
447@end example
448
449GOOPS expands this to something like:
450
451@example
452(define <my-class2>
453 (make <my-metaclass> #:supers (list <object>) #:slots slots))
454@end example
455
456In this case, the value of @code{<my-class2>} is an instance of the more
457specialized class @code{<my-metaclass>}. Note that
458@code{<my-metaclass>} itself must previously have been defined as a
459subclass of @code{<class>}. For a full discussion of when and how it is
460useful to define new metaclasses, see @ref{MOP Specification}.
461
462Now let's make an instance of @code{<my-class2>}:
463
464@example
465(define my-object (make <my-class2> ...))
466@end example
467
468All of the following statements are correct expressions of the
469relationships between @code{my-object}, @code{<my-class2>},
470@code{<my-metaclass>} and @code{<class>}.
471
472@itemize @bullet
473@item
474@code{my-object} is an instance of the class @code{<my-class2>}.
475
476@item
477@code{<my-class2>} is an instance of the class @code{<my-metaclass>}.
478
479@item
480@code{<my-metaclass>} is an instance of the class @code{<class>}.
481
482@item
483The class of @code{my-object} is @code{<my-class2>}.
484
485@item
486The metaclass of @code{my-object} is @code{<my-metaclass>}.
487
488@item
489The class of @code{<my-class2>} is @code{<my-metaclass>}.
490
491@item
492The metaclass of @code{<my-class2>} is @code{<class>}.
493
494@item
495The class of @code{<my-metaclass>} is @code{<class>}.
496
497@item
498The metaclass of @code{<my-metaclass>} is @code{<class>}.
499
500@item
501@code{<my-class2>} is not a metaclass, since it is does not inherit from
502@code{<class>}.
503
504@item
505@code{<my-metaclass>} is a metaclass, since it inherits from
506@code{<class>}.
507@end itemize
508
509@node Class Precedence List
510@subsubsection Class Precedence List
511
512The @dfn{class precedence list} of a class is the list of all direct and
513indirect superclasses of that class, including the class itself.
514
515In the absence of multiple inheritance, the class precedence list is
516ordered straightforwardly, beginning with the class itself and ending
517with @code{<top>}.
518
519For example, given this inheritance hierarchy:
520
521@example
522(define-class <invertebrate> (<object>) @dots{})
523(define-class <echinoderm> (<invertebrate>) @dots{})
524(define-class <starfish> (<echinoderm>) @dots{})
525@end example
526
527the class precedence list of <starfish> would be
528
529@example
530(<starfish> <echinoderm> <invertebrate> <object> <top>)
531@end example
532
533With multiple inheritance, the algorithm is a little more complicated.
534A full description is provided by the GOOPS Tutorial: see @ref{Class
535precedence list}.
536
537``Class precedence list'' is often abbreviated, in documentation and
538Scheme variable names, to @dfn{cpl}.
539
540@node Accessor
541@subsubsection Accessor
542
543An @dfn{accessor} is a generic function with both reference and setter
544methods.
545
546@example
547(define-accessor perimeter)
548@end example
549
550Reference methods for an accessor are defined in the same way as generic
551function methods.
552
553@example
554(define-method (perimeter (s <square>))
555 (* 4 (side-length s)))
556@end example
557
558Setter methods for an accessor are defined by specifying ``(setter
559<accessor-name>)'' as the first parameter of the @code{define-method}
560call.
561
562@example
563(define-method ((setter perimeter) (s <square>) (n <number>))
564 (set! (side-length s) (/ n 4)))
565@end example
566
567Once an appropriate setter method has been defined in this way, it can
568be invoked using the generalized @code{set!} syntax, as in:
569
570@example
571(set! (perimeter s1) 18.3)
572@end example
573
574@node Defining New Classes
575@section Defining New Classes
576
577[ *fixme* Somewhere in this manual there needs to be an introductory
578discussion about GOOPS classes, generic functions and methods, covering
579
580@itemize @bullet
581@item
582how classes encapsulate related items of data in @dfn{slots}
583
584@item
585why it is that, unlike in C++ and Java, a class does not encapsulate the
586methods that act upon the class (at least not in the C++/Java sense)
587
588@item
589how generic functions provide a more general solution that provides for
590dispatch on all argument types, and avoids idiosyncracies like C++'s
591friend classes
592
593@item
594how encapsulation in the sense of data- and code-hiding, or of
595distinguishing interface from implementation, is treated in Guile as an
596orthogonal concept to object orientation, and is the responsibility of
597the module system.
598@end itemize
599
600Some of this is covered in the Tutorial chapter, in @ref{Generic
601functions and methods} - perhaps the best solution would be to expand
602the discussion there. ]
603
604@menu
605* Basic Class Definition::
606* Class Options::
607* Slot Options::
608* Class Definition Internals::
609* Customizing Class Definition::
610* STKlos Compatibility::
611@end menu
612
613@node Basic Class Definition
614@subsection Basic Class Definition
615
616New classes are defined using the @code{define-class} syntax, with
617arguments that specify the classes that the new class should inherit
618from, the direct slots of the new class, and any required class options.
619
620@deffn syntax define-class name (super @dots{}) slot-definition @dots{} . options
621Define a class called @var{name} that inherits from @var{super}s, with
622direct slots defined by @var{slot-definition}s and class options
623@var{options}. The newly created class is bound to the variable name
624@var{name} in the current environment.
625
626Each @var{slot-definition} is either a symbol that names the slot or a
627list,
628
629@example
630(@var{slot-name-symbol} . @var{slot-options})
631@end example
632
633where @var{slot-name-symbol} is a symbol and @var{slot-options} is a
634list with an even number of elements. The even-numbered elements of
635@var{slot-options} (counting from zero) are slot option keywords; the
636odd-numbered elements are the corresponding values for those keywords.
637
638@var{options} is a similarly structured list containing class option
639keywords and corresponding values.
640@end deffn
641
642The standard GOOPS class and slot options are described in the following
643subsections: see @ref{Class Options} and @ref{Slot Options}.
644
645Example 1. Define a class that combines two pre-existing classes by
646inheritance but adds no new slots.
647
648@example
649(define-class <combined> (<tree> <bicycle>))
650@end example
651
652Example 2. Define a @code{regular-polygon} class with slots for side
653length and number of sides that have default values and can be accessed
654via the generic functions @code{side-length} and @code{num-sides}.
655
656@example
657(define-class <regular-polygon> ()
658 (sl #:init-value 1 #:accessor side-length)
659 (ns #:init-value 5 #:accessor num-sides))
660@end example
661
662Example 3. Define a class whose behavior (and that of its instances) is
663customized via an application-defined metaclass.
664
665@example
666(define-class <tcpip-fsm> ()
667 (s #:init-value #f #:accessor state)
668 ...
669 #:metaclass <finite-state-class>)
670@end example
671
672@node Class Options
673@subsection Class Options
674
675@deffn {class option} #:metaclass metaclass
676The @code{#:metaclass} class option specifies the metaclass of the class
677being defined. @var{metaclass} must be a class that inherits from
678@code{<class>}. For an introduction to the use of metaclasses, see
679@ref{Metaobjects and the Metaobject Protocol} and @ref{Metaclass}.
680
681If the @code{#:metaclass} option is absent, GOOPS reuses or constructs a
682metaclass for the new class by calling @code{ensure-metaclass}
683(@pxref{Class Definition Internals,, ensure-metaclass}).
684@end deffn
685
686@deffn {class option} #:name name
687The @code{#:name} class option specifies the new class's name. This
688name is used to identify the class whenever related objects - the class
689itself, its instances and its subclasses - are printed.
690
691If the @code{#:name} option is absent, GOOPS uses the first argument to
692@code{define-class} as the class name.
693@end deffn
694
695@deffn {class option} #:environment environment
696*fixme* Not sure about this one, but I think that the
697@code{#:environment} option specifies the environment in which the
698class's getters and setters are computed and evaluated.
699
700If the @code{#:environment} option is not specified, the class's
701environment defaults to the top-level environment in which the
702@code{define-class} form appears.
703@end deffn
704
705@node Slot Options
706@subsection Slot Options
707
708@deffn {slot option} #:allocation allocation
709The @code{#:allocation} option tells GOOPS how to allocate storage for
710the slot. Possible values for @var{allocation} are
711
712@itemize @bullet
713@item @code{#:instance}
714
715Indicates that GOOPS should create separate storage for this slot in
716each new instance of the containing class (and its subclasses).
717
718@item @code{#:class}
719
720Indicates that GOOPS should create storage for this slot that is shared
721by all instances of the containing class (and its subclasses). In other
722words, a slot in class @var{C} with allocation @code{#:class} is shared
723by all @var{instance}s for which @code{(is-a? @var{instance} @var{c})}.
724
725@item @code{#:each-subclass}
726
727Indicates that GOOPS should create storage for this slot that is shared
728by all @emph{direct} instances of the containing class, and that
729whenever a subclass of the containing class is defined, GOOPS should
730create a new storage for the slot that is shared by all @emph{direct}
731instances of the subclass. In other words, a slot with allocation
732@code{#:each-subclass} is shared by all instances with the same
733@code{class-of}.
734
735@item @code{#:virtual}
736
737Indicates that GOOPS should not allocate storage for this slot. The
738slot definition must also include the @code{#:slot-ref} and
739@code{#:slot-set!} options to specify how to reference and set the value
740for this slot.
741@end itemize
742
743The default value is @code{#:instance}.
744
745Slot allocation options are processed when defining a new class by the
746generic function @code{compute-get-n-set}, which is specialized by the
747class's metaclass. Hence new types of slot allocation can be
748implemented by defining a new metaclass and a method for
749@code{compute-get-n-set} that is specialized for the new metaclass. For
750an example of how to do this, see @ref{Customizing Class Definition}.
751@end deffn
752
753@deffn {slot option} #:slot-ref getter
754@deffnx {slot option} #:slot-set! setter
755The @code{#:slot-ref} and @code{#:slot-set!} options must be specified
756if the slot allocation is @code{#:virtual}, and are ignored otherwise.
757
758@var{getter} should be a closure taking a single @var{instance} parameter
759that returns the current slot value. @var{setter} should be a closure
760taking two parameters - @var{instance} and @var{new-val} - that sets the
761slot value to @var{new-val}.
762@end deffn
763
764@deffn {slot option} #:getter getter
765@deffnx {slot option} #:setter setter
766@deffnx {slot option} #:accessor accessor
767These options, if present, tell GOOPS to create generic function and
768method definitions that can be used to get and set the slot value more
769conveniently than by using @code{slot-ref} and @code{slot-set!}.
770
771@var{getter} specifies a generic function to which GOOPS will add a
772method for getting the slot value. @var{setter} specifies a generic
773function to which GOOPS will add a method for setting the slot value.
774@var{accessor} specifies an accessor to which GOOPS will add methods for
775both getting and setting the slot value.
776
777So if a class includes a slot definition like this:
778
779@example
780(c #:getter get-count #:setter set-count #:accessor count)
781@end example
782
783GOOPS defines generic function methods such that the slot value can be
784referenced using either the getter or the accessor -
785
786@example
787(let ((current-count (get-count obj))) @dots{})
788(let ((current-count (count obj))) @dots{})
789@end example
790
791- and set using either the setter or the accessor -
792
793@example
794(set-count obj (+ 1 current-count))
795(set! (count obj) (+ 1 current-count))
796@end example
797
798Note that
799
800@itemize @bullet
801@item
802with an accessor, the slot value is set using the generalized
803@code{set!} syntax
804
805@item
806in practice, it is unusual for a slot to use all three of these options:
807read-only, write-only and read-write slots would typically use only
808@code{#:getter}, @code{#:setter} and @code{#:accessor} options
809respectively.
810@end itemize
811
812If the specified names are already bound in the top-level environment to
813values that cannot be upgraded to generic functions, those values are
814overwritten during evaluation of the @code{define-class} that contains
815the slot definition. For details, see @ref{Generic Function Internals,,
816ensure-generic}.
817@end deffn
818
819@deffn {slot option} #:init-value init-value
820@deffnx {slot option} #:init-form init-form
821@deffnx {slot option} #:init-thunk init-thunk
822@deffnx {slot option} #:init-keyword init-keyword
823These options provide various ways to specify how to initialize the
824slot's value at instance creation time. @var{init-value} is a fixed
825value. @var{init-thunk} is a procedure of no arguments that is called
826when a new instance is created and should return the desired initial
827slot value. @var{init-form} is an unevaluated expression that gets
828evaluated when a new instance is created and should return the desired
829initial slot value. @var{init-keyword} is a keyword that can be used to
830pass an initial slot value to @code{make} when creating a new instance.
831
832If more than one of these options is specified for the same slot, the
833order of precedence, highest first is
834
835@itemize @bullet
836@item
837@code{#:init-keyword}, if @var{init-keyword} is present in the options
838passed to @code{make}
839
840@item
841@code{#:init-thunk}, @code{#:init-form} or @code{#:init-value}.
842@end itemize
843
844If the slot definition contains more than one initialization option of
845the same precedence, the later ones are ignored. If a slot is not
846initialized at all, its value is unbound.
847
848In general, slots that are shared between more than one instance are
849only initialized at new instance creation time if the slot value is
850unbound at that time. However, if the new instance creation specifies
851a valid init keyword and value for a shared slot, the slot is
852re-initialized regardless of its previous value.
853
854Note, however, that the power of GOOPS' metaobject protocol means that
855everything written here may be customized or overridden for particular
856classes! The slot initializations described here are performed by the least
857specialized method of the generic function @code{initialize}, whose
858signature is
859
860@example
861(define-method (initialize (object <object>) initargs) ...)
862@end example
863
864The initialization of instances of any given class can be customized by
865defining a @code{initialize} method that is specialized for that class,
866and the author of the specialized method may decide to call
867@code{next-method} - which will result in a call to the next less
868specialized @code{initialize} method - at any point within the
869specialized code, or maybe not at all. In general, therefore, the
870initialization mechanisms described here may be modified or overridden by
871more specialized code, or may not be supported at all for particular
872classes.
873@end deffn
874
875@node Class Definition Internals
876@subsection Class Definition Internals
877
878Implementation notes: @code{define-class} expands to an expression which
879
880@itemize @bullet
881@item
882checks that it is being evaluated only at top level
883
884@item
885defines any accessors that are implied by the @var{slot-definition}s
886
887@item
888uses @code{class} to create the new class (@pxref{Class Definition
889Internals,, class})
890
891@item
892checks for a previous class definition for @var{name} and, if found,
893handles the redefinition by invoking @code{class-redefinition}
894(@pxref{Redefining a Class}).
895@end itemize
896
897@deffn syntax class name (super @dots{}) slot-definition @dots{} . options
898Return a newly created class that inherits from @var{super}s, with
899direct slots defined by @var{slot-definition}s and class options
900@var{options}. For the format of @var{slot-definition}s and
901@var{options}, see @ref{Basic Class Definition,, define-class}.
902@end deffn
903
904Implementation notes: @code{class} expands to an expression which
905
906@itemize @bullet
907@item
908processes the class and slot definition options to check that they are
909well-formed, to convert the @code{#:init-form} option to an
910@code{#:init-thunk} option, to supply a default environment parameter
911(the current top-level environment) and to evaluate all the bits that
912need to be evaluated
913
914@item
915calls @code{make-class} to create the class with the processed and
916evaluated parameters.
917@end itemize
918
919@deffn procedure make-class supers slots . options
920Return a newly created class that inherits from @var{supers}, with
921direct slots defined by @var{slots} and class options @var{options}.
922For the format of @var{slots} and @var{options}, see @ref{Basic Class
923Definition,, define-class}, except note that for @code{make-class},
924@var{slots} and @var{options} are separate list parameters: @var{slots}
925here is a list of slot definitions.
926@end deffn
927
928Implementation notes: @code{make-class}
929
930@itemize @bullet
931@item
932adds @code{<object>} to the @var{supers} list if @var{supers} is empty
933or if none of the classes in @var{supers} have @code{<object>} in their
934class precedence list
935
936@item
937defaults the @code{#:environment}, @code{#:name} and @code{#:metaclass}
938options, if they are not specified by @var{options}, to the current
939top-level environment, the unbound value, and @code{(ensure-metaclass
940@var{supers})} respectively (@pxref{Class Definition Internals,,
941ensure-metaclass})
942
943@item
944checks for duplicate classes in @var{supers} and duplicate slot names in
945@var{slots}, and signals an error if there are any duplicates
946
947@item
948calls @code{make}, passing the metaclass as the first parameter and all
949other parameters as option keywords with values.
950@end itemize
951
952@deffn procedure ensure-metaclass supers env
953Return a metaclass suitable for a class that inherits from the list of
954classes in @var{supers}. The returned metaclass is the union by
955inheritance of the metaclasses of the classes in @var{supers}.
956
957In the simplest case, where all the @var{supers} are straightforward
958classes with metaclass @code{<class>}, the returned metaclass is just
959@code{<class>}.
960
961For a more complex example, suppose that @var{supers} contained one
962class with metaclass @code{<operator-class>} and one with metaclass
963@code{<foreign-object-class>}. Then the returned metaclass would be a
964class that inherits from both @code{<operator-class>} and
965@code{<foreign-object-class>}.
966
967If @var{supers} is the empty list, @code{ensure-metaclass} returns the
968default GOOPS metaclass @code{<class>}.
969
970GOOPS keeps a list of the metaclasses created by
971@code{ensure-metaclass}, so that each required type of metaclass only
972has to be created once.
973
974The @code{env} parameter is ignored.
975@end deffn
976
977@deffn procedure ensure-metaclass-with-supers meta-supers
978@code{ensure-metaclass-with-supers} is an internal procedure used by
979@code{ensure-metaclass} (@pxref{Class Definition Internals,,
980ensure-metaclass}). It returns a metaclass that is the union by
981inheritance of the metaclasses in @var{meta-supers}.
982@end deffn
983
984The internals of @code{make}, which is ultimately used to create the new
985class object, are described in @ref{Customizing Instance Creation},
986which covers the creation and initialization of instances in general.
987
988@node Customizing Class Definition
989@subsection Customizing Class Definition
990
991During the initialization of a new class, GOOPS calls a number of generic
992functions with the newly allocated class instance as the first
993argument. Specifically, GOOPS calls the generic function
994
995@itemize @bullet
996@item
997(initialize @var{class} @dots{})
998@end itemize
999
1000where @var{class} is the newly allocated class instance, and the default
1001@code{initialize} method for arguments of type @code{<class>} calls the
1002generic functions
1003
1004@itemize @bullet
1005@item
1006(compute-cpl @var{class})
1007
1008@item
1009(compute-slots @var{class})
1010
1011@item
1012(compute-get-n-set @var{class} @var{slot-def}), for each of the slot
1013definitions returned by @code{compute-slots}
1014
1015@item
1016(compute-getter-method @var{class} @var{slot-def}), for each of the
1017slot definitions returned by @code{compute-slots} that includes a
1018@code{#:getter} or @code{#:accessor} slot option
1019
1020@item
1021(compute-setter-method @var{class} @var{slot-def}), for each of the
1022slot definitions returned by @code{compute-slots} that includes a
1023@code{#:setter} or @code{#:accessor} slot option.
1024@end itemize
1025
1026If the metaclass of the new class is something more specialized than the
1027default @code{<class>}, then the type of @var{class} in the calls above
1028is more specialized than @code{<class>}, and hence it becomes possible
1029to define generic function methods, specialized for the new class's
1030metaclass, that can modify or override the default behaviour of
1031@code{initialize}, @code{compute-cpl} or @code{compute-get-n-set}.
1032
1033@code{compute-cpl} computes the class precedence list (``CPL'') for the
1034new class (@pxref{Class precedence list}), and returns it as a list of
1035class objects. The CPL is important because it defines a superclass
1036ordering that is used, when a generic function is invoked upon an
1037instance of the class, to decide which of the available generic function
1038methods is the most specific. Hence @code{compute-cpl} could be
1039customized in order to modify the CPL ordering algorithm for all classes
1040with a special metaclass.
1041
1042The default CPL algorithm is encapsulated by the @code{compute-std-cpl}
1043procedure, which is in turn called by the default @code{compute-cpl}
1044method.
1045
1046@deffn procedure compute-std-cpl class
1047Compute and return the class precedence list for @var{class} according
1048to the algorithm described in @ref{Class precedence list}.
1049@end deffn
1050
1051@code{compute-slots} computes and returns a list of all slot definitions
1052for the new class. By default, this list includes the direct slot
1053definitions from the @code{define-class} form, plus the slot definitions
1054that are inherited from the new class's superclasses. The default
1055@code{compute-slots} method uses the CPL computed by @code{compute-cpl}
1056to calculate this union of slot definitions, with the rule that slots
1057inherited from superclasses are shadowed by direct slots with the same
1058name. One possible reason for customizing @code{compute-slots} would be
1059to implement an alternative resolution strategy for slot name conflicts.
1060
1061@code{compute-get-n-set} computes the low-level closures that will be
1062used to get and set the value of a particular slot, and returns them in
1063a list with two elements.
1064
1065The closures returned depend on how storage for that slot is allocated.
1066The standard @code{compute-get-n-set} method, specialized for classes of
1067type @code{<class>}, handles the standard GOOPS values for the
1068@code{#:allocation} slot option (@pxref{Slot Options,, allocation}). By
1069defining a new @code{compute-get-n-set} method for a more specialized
1070metaclass, it is possible to support new types of slot allocation.
1071
1072Suppose you wanted to create a large number of instances of some class
1073with a slot that should be shared between some but not all instances of
1074that class - say every 10 instances should share the same slot storage.
1075The following example shows how to implement and use a new type of slot
1076allocation to do this.
1077
1078@example
1079(define-class <batched-allocation-metaclass> (<class>))
1080
1081(let ((batch-allocation-count 0)
1082 (batch-get-n-set #f))
1083 (define-method (compute-get-n-set (class <batched-allocation-metaclass>) s)
1084 (case (slot-definition-allocation s)
1085 ((#:batched)
1086 ;; If we've already used the same slot storage for 10 instances,
1087 ;; reset variables.
1088 (if (= batch-allocation-count 10)
1089 (begin
1090 (set! batch-allocation-count 0)
1091 (set! batch-get-n-set #f)))
1092 ;; If we don't have a current pair of get and set closures,
1093 ;; create one. make-closure-variable returns a pair of closures
1094 ;; around a single Scheme variable - see goops.scm for details.
1095 (or batch-get-n-set
1096 (set! batch-get-n-set (make-closure-variable)))
1097 ;; Increment the batch allocation count.
1098 (set! batch-allocation-count (+ batch-allocation-count 1))
1099 batch-get-n-set)
1100
1101 ;; Call next-method to handle standard allocation types.
1102 (else (next-method)))))
1103
1104(define-class <class-using-batched-slot> ()
1105 ...
1106 (c #:allocation #:batched)
1107 ...
1108 #:metaclass <batched-allocation-metaclass>)
1109@end example
1110
1111The usage of @code{compute-getter-method} and @code{compute-setter-method}
1112is described in @ref{MOP Specification}.
1113
1114@code{compute-cpl} and @code{compute-get-n-set} are called by the
1115standard @code{initialize} method for classes whose metaclass is
1116@code{<class>}. But @code{initialize} itself can also be modified, by
1117defining an @code{initialize} method specialized to the new class's
1118metaclass. Such a method could complete override the standard
1119behaviour, by not calling @code{(next-method)} at all, but more
1120typically it would perform additional class initialization steps before
1121and/or after calling @code{(next-method)} for the standard behaviour.
1122
1123@node STKlos Compatibility
1124@subsection STKlos Compatibility
1125
1126If the STKlos compatibility module is loaded, @code{define-class} is
1127overwritten by a STKlos-specific definition; the standard GOOPS
1128definition of @code{define-class} remains available in
1129@code{standard-define-class}.
1130
1131@deffn syntax standard-define-class name (super @dots{}) slot-definition @dots{} . options
1132@code{standard-define-class} is equivalent to the standard GOOPS
1133@code{define-class}.
1134@end deffn
1135
1136@node Creating Instances
1137@section Creating Instances
1138
1139@menu
1140* Basic Instance Creation::
1141* Customizing Instance Creation::
1142@end menu
1143
1144@node Basic Instance Creation
1145@subsection Basic Instance Creation
1146
1147To create a new instance of any GOOPS class, use the generic function
1148@code{make} or @code{make-instance}, passing the required class and any
1149appropriate instance initialization arguments as keyword and value
1150pairs. Note that @code{make} and @code{make-instances} are aliases for
1151each other - their behaviour is identical.
1152
1153@deffn generic make
1154@deffnx method make (class <class>) . initargs
1155Create and return a new instance of class @var{class}, initialized using
1156@var{initargs}.
1157
1158In theory, @var{initargs} can have any structure that is understood by
1159whatever methods get applied when the @code{initialize} generic function
1160is applied to the newly allocated instance.
1161
1162In practice, specialized @code{initialize} methods would normally call
1163@code{(next-method)}, and so eventually the standard GOOPS
1164@code{initialize} methods are applied. These methods expect
1165@var{initargs} to be a list with an even number of elements, where
1166even-numbered elements (counting from zero) are keywords and
1167odd-numbered elements are the corresponding values.
1168
1169GOOPS processes initialization argument keywords automatically for slots
1170whose definition includes the @code{#:init-keyword} option (@pxref{Slot
1171Options,, init-keyword}). Other keyword value pairs can only be
1172processed by an @code{initialize} method that is specialized for the new
1173instance's class. Any unprocessed keyword value pairs are ignored.
1174@end deffn
1175
1176@deffn generic make-instance
1177@deffnx method make-instance (class <class>) . initargs
1178@code{make-instance} is an alias for @code{make}.
1179@end deffn
1180
1181@node Customizing Instance Creation
1182@subsection Customizing Instance Creation
1183
1184@code{make} itself is a generic function. Hence the @code{make}
1185invocation itself can be customized in the case where the new instance's
1186metaclass is more specialized than the default @code{<class>}, by
1187defining a @code{make} method that is specialized to that metaclass.
1188
1189Normally, however, the method for classes with metaclass @code{<class>}
1190will be applied. This method calls two generic functions:
1191
1192@itemize @bullet
1193@item
1194(allocate-instance @var{class} . @var{initargs})
1195
1196@item
1197(initialize @var{instance} . @var{initargs})
1198@end itemize
1199
1200@code{allocate-instance} allocates storage for and returns the new
1201instance, uninitialized. You might customize @code{allocate-instance},
1202for example, if you wanted to provide a GOOPS wrapper around some other
1203object programming system.
1204
1205To do this, you would create a specialized metaclass, which would act as
1206the metaclass for all classes and instances from the other system. Then
1207define an @code{allocate-instance} method, specialized to that
1208metaclass, which calls a Guile primitive C function, which in turn
1209allocates the new instance using the interface of the other object
1210system.
1211
1212In this case, for a complete system, you would also need to customize a
1213number of other generic functions like @code{make} and
1214@code{initialize}, so that GOOPS knows how to make classes from the
1215other system, access instance slots, and so on.
1216
1217@code{initialize} initializes the instance that is returned by
1218@code{allocate-instance}. The standard GOOPS methods perform
1219initializations appropriate to the instance class.
1220
1221@itemize @bullet
1222@item
1223At the least specialized level, the method for instances of type
1224@code{<object>} performs internal GOOPS instance initialization, and
1225initializes the instance's slots according to the slot definitions and
1226any slot initialization keywords that appear in @var{initargs}.
1227
1228@item
1229The method for instances of type @code{<class>} calls
1230@code{(next-method)}, then performs the class initializations described
1231in @ref{Customizing Class Definition}.
1232
1233@item
1234and so on for generic functions, method, operator classes @dots{}
1235@end itemize
1236
1237Similarly, you can customize the initialization of instances of any
1238application-defined class by defining an @code{initialize} method
1239specialized to that class.
1240
1241Imagine a class whose instances' slots need to be initialized at
1242instance creation time by querying a database. Although it might be
1243possible to achieve this a combination of @code{#:init-thunk} keywords
1244and closures in the slot definitions, it is neater to write an
1245@code{initialize} method for the class that queries the database once
1246and initializes all the dependent slot values according to the results.
1247
1248@node Accessing Slots
1249@section Accessing Slots
1250
1251The definition of a slot contains at the very least a slot name, and may
1252also contain various slot options, including getter, setter and/or
1253accessor functions for the slot.
1254
1255It is always possible to access slots by name, using the various
1256``slot-ref'' and ``slot-set!'' procedures described in the following
1257subsections. For example,
1258
1259@example
1260(define-class <my-class> () ;; Define a class with slots
1261 (count #:init-value 0) ;; named "count" and "cache".
1262 (cache #:init-value '())
1263 @dots{})
1264
1265(define inst (make <my-class>)) ;; Make an instance of this class.
1266
1267(slot-set! inst 'count 5) ;; Set the value of the "count"
1268 ;; slot to 5.
1269
1270(slot-set! inst 'cache ;; Modify the value of the
1271 (cons (cons "^it" "It") ;; "cache" slot.
1272 (slot-ref inst 'cache)))
1273@end example
1274
1275If a slot definition includes a getter, setter or accessor function,
1276these can be used instead of @code{slot-ref} and @code{slot-set!} to
1277access the slot.
1278
1279@example
1280(define-class <adv-class> () ;; Define a new class whose slots
1281 (count #:setter set-count) ;; use a getter, a setter and
1282 (cache #:accessor cache) ;; an accessor.
1283 (csize #:getter cache-size)
1284 @dots{})
1285
1286(define inst (make <adv-class>)) ;; Make an instance of this class.
1287
1288(set-count inst 5) ;; Set the value of the "count"
1289 ;; slot to 5.
1290
1291(set! (cache inst) ;; Modify the value of the
1292 (cons (cons "^it" "It") ;; "cache" slot.
1293 (cache inst)))
1294
1295(let ((size (cache-size inst))) ;; Get the value of the "csize"
1296 @dots{}) ;; slot.
1297@end example
1298
1299Whichever of these methods is used to access slots, GOOPS always calls
1300the low-level @dfn{getter} and @dfn{setter} closures for the slot to get
1301and set its value. These closures make sure that the slot behaves
1302according to the @code{#:allocation} type that was specified in the slot
1303definition (@pxref{Slot Options,, allocation}). (For more about these
1304closures, see @ref{Customizing Class Definition,, compute-get-n-set}.)
1305
1306@menu
1307* Instance Slots::
1308* Class Slots::
1309* Handling Slot Access Errors::
1310@end menu
1311
1312@node Instance Slots
1313@subsection Instance Slots
1314
1315Any slot, regardless of its allocation, can be queried, referenced and
1316set using the following four primitive procedures.
1317
1318@deffn {primitive procedure} slot-exists? obj slot-name
1319Return @code{#t} if @var{obj} has a slot with name @var{slot-name},
1320otherwise @code{#f}.
1321@end deffn
1322
1323@deffn {primitive procedure} slot-bound? obj slot-name
1324Return @code{#t} if the slot named @var{slot-name} in @var{obj} has a
1325value, otherwise @code{#f}.
1326
1327@code{slot-bound?} calls the generic function @code{slot-missing} if
1328@var{obj} does not have a slot called @var{slot-name} (@pxref{Handling
1329Slot Access Errors, slot-missing}).
1330@end deffn
1331
1332@deffn {primitive procedure} slot-ref obj slot-name
1333Return the value of the slot named @var{slot-name} in @var{obj}.
1334
1335@code{slot-ref} calls the generic function @code{slot-missing} if
1336@var{obj} does not have a slot called @var{slot-name} (@pxref{Handling
1337Slot Access Errors, slot-missing}).
1338
1339@code{slot-ref} calls the generic function @code{slot-unbound} if the
1340named slot in @var{obj} does not have a value (@pxref{Handling Slot
1341Access Errors, slot-unbound}).
1342@end deffn
1343
1344@deffn {primitive procedure} slot-set! obj slot-name value
1345Set the value of the slot named @var{slot-name} in @var{obj} to @var{value}.
1346
1347@code{slot-set!} calls the generic function @code{slot-missing} if
1348@var{obj} does not have a slot called @var{slot-name} (@pxref{Handling
1349Slot Access Errors, slot-missing}).
1350@end deffn
1351
1352GOOPS stores information about slots in class metaobjects. Internally,
1353all of these procedures work by looking up the slot definition for the
1354slot named @var{slot-name} in the class metaobject for @code{(class-of
1355@var{obj})}, and then using the slot definition's ``getter'' and
1356``setter'' closures to get and set the slot value.
1357
1358The next four procedures differ from the previous ones in that they take
1359the class metaobject as an explicit argument, rather than assuming
1360@code{(class-of @var{obj})}. Therefore they allow you to apply the
1361``getter'' and ``setter'' closures of a slot definition in one class to
1362an instance of a different class.
1363
1364[ *fixme* I have no idea why this is useful! Perhaps when a slot in
1365@code{(class-of @var{obj})} shadows a slot with the same name in one of
1366its superclasses? There should be an enlightening example here. ]
1367
1368@deffn {primitive procedure} slot-exists-using-class? class obj slot-name
1369Return @code{#t} if the class metaobject @var{class} has a slot
1370definition for a slot with name @var{slot-name}, otherwise @code{#f}.
1371@end deffn
1372
1373@deffn {primitive procedure} slot-bound-using-class? class obj slot-name
1374Return @code{#t} if applying @code{slot-ref-using-class} to the same
1375arguments would call the generic function @code{slot-unbound}, otherwise
1376@code{#f}.
1377
1378@code{slot-bound-using-class?} calls the generic function
1379@code{slot-missing} if @var{class} does not have a slot definition for a
1380slot called @var{slot-name} (@pxref{Handling Slot Access Errors,
1381slot-missing}).
1382@end deffn
1383
1384@deffn {primitive procedure} slot-ref-using-class class obj slot-name
1385Apply the ``getter'' closure for the slot named @var{slot-name} in
1386@var{class} to @var{obj}, and return its result.
1387
1388@code{slot-ref-using-class} calls the generic function
1389@code{slot-missing} if @var{class} does not have a slot definition for a
1390slot called @var{slot-name} (@pxref{Handling Slot Access Errors,
1391slot-missing}).
1392
1393@code{slot-ref-using-class} calls the generic function
1394@code{slot-unbound} if the application of the ``getter'' closure to
1395@var{obj} returns an unbound value (@pxref{Handling Slot Access Errors,
1396slot-unbound}).
1397@end deffn
1398
1399@deffn {primitive procedure} slot-set-using-class! class obj slot-name value
1400Apply the ``setter'' closure for the slot named @var{slot-name} in
1401@var{class} to @var{obj} and @var{value}.
1402
1403@code{slot-set-using-class!} calls the generic function
1404@code{slot-missing} if @var{class} does not have a slot definition for a
1405slot called @var{slot-name} (@pxref{Handling Slot Access Errors,
1406slot-missing}).
1407@end deffn
1408
1409@node Class Slots
1410@subsection Class Slots
1411
1412Slots whose allocation is per-class rather than per-instance can be
1413referenced and set without needing to specify any particular instance.
1414
1415@deffn procedure class-slot-ref class slot-name
1416Return the value of the slot named @var{slot-name} in class @var{class}.
1417The named slot must have @code{#:class} or @code{#:each-subclass}
1418allocation (@pxref{Slot Options,, allocation}).
1419
1420If there is no such slot with @code{#:class} or @code{#:each-subclass}
1421allocation, @code{class-slot-ref} calls the @code{slot-missing} generic
1422function with arguments @var{class} and @var{slot-name}. Otherwise, if
1423the slot value is unbound, @code{class-slot-ref} calls the
1424@code{slot-missing} generic function, with the same arguments.
1425@end deffn
1426
1427@deffn procedure class-slot-set! class slot-name value
1428Set the value of the slot named @var{slot-name} in class @var{class} to
1429@var{value}. The named slot must have @code{#:class} or
1430@code{#:each-subclass} allocation (@pxref{Slot Options,, allocation}).
1431
1432If there is no such slot with @code{#:class} or @code{#:each-subclass}
1433allocation, @code{class-slot-ref} calls the @code{slot-missing} generic
1434function with arguments @var{class} and @var{slot-name}.
1435@end deffn
1436
1437@node Handling Slot Access Errors
1438@subsection Handling Slot Access Errors
1439
1440GOOPS calls one of the following generic functions when a ``slot-ref''
1441or ``slot-set!'' call specifies a non-existent slot name, or tries to
1442reference a slot whose value is unbound.
1443
1444@deffn generic slot-missing
1445@deffnx method slot-missing (class <class>) slot-name
1446@deffnx method slot-missing (class <class>) (object <object>) slot-name
1447@deffnx method slot-missing (class <class>) (object <object>) slot-name value
1448When an application attempts to reference or set a class or instance
1449slot by name, and the slot name is invalid for the specified @var{class}
1450or @var{object}, GOOPS calls the @code{slot-missing} generic function.
1451
1452The default methods all call @code{goops-error} with an appropriate
1453message.
1454@end deffn
1455
1456@deffn generic slot-unbound
1457@deffnx method slot-unbound (object <object>)
1458@deffnx method slot-unbound (class <class>) slot-name
1459@deffnx method slot-unbound (class <class>) (object <object>) slot-name
1460When an application attempts to reference a class or instance slot, and
1461the slot's value is unbound, GOOPS calls the @code{slot-unbound} generic
1462function.
1463
1464The default methods all call @code{goops-error} with an appropriate
1465message.
1466@end deffn
1467
1468@node Creating Generic Functions
1469@section Creating Generic Functions
1470
1471A generic function is a collection of methods, with rules for
1472determining which of the methods should be applied for any given
1473invocation of the generic function.
1474
1475GOOPS represents generic functions as metaobjects of the class
1476@code{<generic>} (or one of its subclasses).
1477
1478@menu
1479* Basic Generic Function Creation::
1480* Generic Function Internals::
1481* Extending Guiles Primitives::
1482@end menu
1483
1484@node Basic Generic Function Creation
1485@subsection Basic Generic Function Creation
1486
1487The following forms may be used to bind a variable to a generic
1488function. Depending on that variable's pre-existing value, the generic
1489function may be created empty - with no methods - or it may contain
1490methods that are inferred from the pre-existing value.
1491
1492It is not, in general, necessary to use @code{define-generic} or
1493@code{define-accessor} before defining methods for the generic function
1494using @code{define-method}, since @code{define-method} will
1495automatically interpolate a @code{define-generic} call, or upgrade an
1496existing generic to an accessor, if that is implied by the
1497@code{define-method} call. Note in particular that,
1498if the specified variable already has a @emph{generic function} value,
1499@code{define-generic} and @code{define-accessor} will @emph{discard} it!
1500Obviously it is application-dependent whether this is desirable or not.
1501
1502If, for example, you wanted to extend @code{+} for a class representing
1503a new numerical type, you probably want to inherit any existing methods
1504for @code{+} and so should not use @code{define-generic}. If, on the
1505other hand, you do not want to risk inheriting methods whose behaviour
1506might surprise you, you can use @code{define-generic} or
1507@code{define-accessor} to wipe the slate clean.
1508
1509@deffn syntax define-generic symbol
1510Create a generic function with name @var{symbol} and bind it to the
1511variable @var{symbol}.
1512
1513If the variable @var{symbol} was previously bound to a Scheme procedure
1514(or procedure-with-setter), the old procedure (and setter) is
1515incorporated into the new generic function as its default procedure (and
1516setter). Any other previous value that was bound to @var{symbol},
1517including an existing generic function, is overwritten by the new
1518generic function.
1519@end deffn
1520
1521@deffn syntax define-accessor symbol
1522Create an accessor with name @var{symbol} and bind it to the variable
1523@var{symbol}.
1524
1525If the variable @var{symbol} was previously bound to a Scheme procedure
1526(or procedure-with-setter), the old procedure (and setter) is
1527incorporated into the new accessor as its default procedure (and
1528setter). Any other previous value that was bound to @var{symbol},
1529including an existing generic function or accessor, is overwritten by
1530the new definition.
1531@end deffn
1532
1533@node Generic Function Internals
1534@subsection Generic Function Internals
1535
1536@code{define-generic} calls @code{ensure-generic} to upgrade a
1537pre-existing procedure value, or @code{make} with metaclass
1538@code{<generic>} to create a new generic function.
1539
1540@code{define-accessor} calls @code{ensure-accessor} to upgrade a
1541pre-existing procedure value, or @code{make-accessor} to create a new
1542accessor.
1543
1544@deffn procedure ensure-generic old-definition [name]
1545Return a generic function with name @var{name}, if possible by using or
1546upgrading @var{old-definition}. If unspecified, @var{name} defaults to
1547@code{#f}.
1548
1549If @var{old-definition} is already a generic function, it is returned
1550unchanged.
1551
1552If @var{old-definition} is a Scheme procedure or procedure-with-setter,
1553@code{ensure-generic} returns a new generic function that uses
1554@var{old-definition} for its default procedure and setter.
1555
1556Otherwise @code{ensure-generic} returns a new generic function with no
1557defaults and no methods.
1558@end deffn
1559
1560@deffn procedure make-generic [name]
1561Return a new generic function with name @code{(car @var{name})}. If
1562unspecified, @var{name} defaults to @code{#f}.
1563@end deffn
1564
1565@code{ensure-generic} calls @code{make} with metaclasses
1566@code{<generic>} and @code{<generic-with-setter>}, depending on the
1567previous value of the variable that it is trying to upgrade.
1568
1569@code{make-generic} is a simple wrapper for @code{make} with metaclass
1570@code{<generic>}.
1571
1572@deffn procedure ensure-accessor proc [name]
1573Return an accessor with name @var{name}, if possible by using or
1574upgrading @var{proc}. If unspecified, @var{name} defaults to @code{#f}.
1575
1576If @var{proc} is already an accessor, it is returned unchanged.
1577
1578If @var{proc} is a Scheme procedure, procedure-with-setter or generic
1579function, @code{ensure-accessor} returns an accessor that reuses the
1580reusable elements of @var{proc}.
1581
1582Otherwise @code{ensure-accessor} returns a new accessor with no defaults
1583and no methods.
1584@end deffn
1585
1586@deffn procedure make-accessor [name]
1587Return a new accessor with name @code{(car @var{name})}. If
1588unspecified, @var{name} defaults to @code{#f}.
1589@end deffn
1590
1591@code{ensure-accessor} calls @code{make} with
1592metaclass @code{<generic-with-setter>}, as well as calls to
1593@code{ensure-generic}, @code{make-accessor} and (tail recursively)
1594@code{ensure-accessor}.
1595
1596@code{make-accessor} calls @code{make} twice, first
1597with metaclass @code{<generic>} to create a generic function for the
1598setter, then with metaclass @code{<generic-with-setter>} to create the
1599accessor, passing the setter generic function as the value of the
1600@code{#:setter} keyword.
1601
1602@node Extending Guiles Primitives
1603@subsection Extending Guile's Primitives
1604
1605When GOOPS is loaded, many of Guile's primitive procedures can be
1606extended by giving them a generic function definition that operates
1607in conjunction with their normal C-coded implementation. For
1608primitives that are extended in this way, the result from the user-
1609or application-level point of view is that the extended primitive
1610behaves exactly like a generic function with the C-coded implementation
1611as its default method.
1612
1613The @code{generic-capability?} predicate should be used to determine
1614whether a particular primitive is extensible in this way.
1615
1616@deffn {primitive procedure} generic-capability? primitive
1617Return @code{#t} if @var{primitive} can be extended by giving it a
1618generic function definition, otherwise @code{#f}.
1619@end deffn
1620
1621Even when a primitive procedure is extensible like this, its generic
1622function definition is not created until it is needed by a call to
1623@code{define-method}, or until the application explicitly requests it
1624by calling @code{enable-primitive-generic!}.
1625
1626@deffn {primitive procedure} enable-primitive-generic! primitive
1627Force the creation of a generic function definition for
1628@var{primitive}.
1629@end deffn
1630
1631Once the generic function definition for a primitive has been created,
1632it can be retrieved using @code{primitive-generic-generic}.
1633
1634@deffn {primitive procedure} primitive-generic-generic primitive
1635Return the generic function definition of @var{primitive}.
1636
1637@code{primitive-generic-generic} raises an error if @var{primitive}
1638is not a primitive with generic capability, or if its generic capability
1639has not yet been enabled, whether implicitly (by @code{define-method})
1640or explicitly (by @code{enable-primitive-generic!}).
1641@end deffn
1642
1643Note that the distinction between, on the one hand, primitives with
1644additional generic function definitions and, on the other hand, generic
1645functions with a default method, may disappear when GOOPS is fully
1646integrated into the core of Guile. Consequently, the
1647procedures described in this section may disappear as well.
1648
1649@node Adding Methods to Generic Functions
1650@section Adding Methods to Generic Functions
1651
1652@menu
1653* Basic Method Definition::
1654* Method Definition Internals::
1655@end menu
1656
1657@node Basic Method Definition
1658@subsection Basic Method Definition
1659
1660To add a method to a generic function, use the @code{define-method} form.
1661
1662@deffn syntax define-method (generic parameter @dots{}) . body
1663Define a method for the generic function or accessor @var{generic} with
1664parameters @var{parameter}s and body @var{body}.
1665
1666@var{generic} is a generic function. If @var{generic} is a variable
1667which is not yet bound to a generic function object, the expansion of
1668@code{define-method} will include a call to @code{define-generic}. If
1669@var{generic} is @code{(setter @var{generic-with-setter})}, where
1670@var{generic-with-setter} is a variable which is not yet bound to a
1671generic-with-setter object, the expansion will include a call to
1672@code{define-accessor}.
1673
1674Each @var{parameter} must be either a symbol or a two-element list
1675@code{(@var{symbol} @var{class})}. The symbols refer to variables in
1676the @var{body} that will be bound to the parameters supplied by the
1677caller when calling this method. The @var{class}es, if present,
1678specify the possible combinations of parameters to which this method
1679can be applied.
1680
1681@var{body} is the body of the method definition.
1682@end deffn
1683
1684@code{define-method} expressions look a little like normal Scheme
1685procedure definitions of the form
1686
1687@example
1688(define (name formals @dots{}) . body)
1689@end example
1690
1691The most important difference is that each formal parameter, apart from the
1692possible ``rest'' argument, can be qualified by a class name:
1693@code{@var{formal}} becomes @code{(@var{formal} @var{class})}. The
1694meaning of this qualification is that the method being defined
1695will only be applicable in a particular generic function invocation if
1696the corresponding argument is an instance of @code{@var{class}} (or one of
1697its subclasses). If more than one of the formal parameters is qualified
1698in this way, then the method will only be applicable if each of the
1699corresponding arguments is an instance of its respective qualifying class.
1700
1701Note that unqualified formal parameters act as though they are qualified
1702by the class @code{<top>}, which GOOPS uses to mean the superclass of
1703all valid Scheme types, including both primitive types and GOOPS classes.
1704
1705For example, if a generic function method is defined with
1706@var{parameter}s @code{((s1 <square>) (n <number>))}, that method is
1707only applicable to invocations of its generic function that have two
1708parameters where the first parameter is an instance of the
1709@code{<square>} class and the second parameter is a number.
1710
1711If a generic function is invoked with a combination of parameters for which
1712there is no applicable method, GOOPS raises an error. For more about
1713invocation error handling, and generic function invocation in general,
1714see @ref{Invoking Generic Functions}.
1715
1716@node Method Definition Internals
1717@subsection Method Definition Internals
1718
1719@code{define-method}
1720
1721@itemize @bullet
1722@item
1723checks the form of the first parameter, and applies the following steps
1724to the accessor's setter if it has the @code{(setter @dots{})} form
1725
1726@item
1727interpolates a call to @code{define-generic} or @code{define-accessor}
1728if a generic function is not already defined with the supplied name
1729
1730@item
1731calls @code{method} with the @var{parameter}s and @var{body}, to make a
1732new method instance
1733
1734@item
1735calls @code{add-method!} to add this method to the relevant generic
1736function.
1737@end itemize
1738
1739@deffn syntax method (parameter @dots{}) . body
1740Make a method whose specializers are defined by the classes in
1741@var{parameter}s and whose procedure definition is constructed from the
1742@var{parameter} symbols and @var{body} forms.
1743
1744The @var{parameter} and @var{body} parameters should be as for
1745@code{define-method} (@pxref{Basic Method Definition,, define-method}).
1746@end deffn
1747
1748@code{method}
1749
1750@itemize @bullet
1751@item
1752extracts formals and specializing classes from the @var{parameter}s,
1753defaulting the class for unspecialized parameters to @code{<top>}
1754
1755@item
1756creates a closure using the formals and the @var{body} forms
1757
1758@item
1759calls @code{make} with metaclass @code{<method>} and the specializers
1760and closure using the @code{#:specializers} and @code{#:procedure}
1761keywords.
1762@end itemize
1763
1764@deffn procedure make-method specializers procedure
1765Make a method using @var{specializers} and @var{procedure}.
1766
1767@var{specializers} should be a list of classes that specifies the
1768parameter combinations to which this method will be applicable.
1769
1770@var{procedure} should be the closure that will applied to the generic
1771function parameters when this method is invoked.
1772@end deffn
1773
1774@code{make-method} is a simple wrapper around @code{make} with metaclass
1775@code{<method>}.
1776
1777@deffn generic add-method! target method
1778Generic function for adding method @var{method} to @var{target}.
1779@end deffn
1780
1781@deffn method add-method! (generic <generic>) (method <method>)
1782Add method @var{method} to the generic function @var{generic}.
1783@end deffn
1784
1785@deffn method add-method! (proc <procedure>) (method <method>)
1786If @var{proc} is a procedure with generic capability (@pxref{Extending
1787Guiles Primitives,, generic-capability?}), upgrade it to a
1788primitive generic and add @var{method} to its generic function
1789definition.
1790@end deffn
1791
1792@deffn method add-method! (pg <primitive-generic>) (method <method>)
1793Add method @var{method} to the generic function definition of @var{pg}.
1794
1795Implementation: @code{(add-method! (primitive-generic-generic pg) method)}.
1796@end deffn
1797
1798@deffn method add-method! (whatever <top>) (method <method>)
1799Raise an error indicating that @var{whatever} is not a valid generic
1800function.
1801@end deffn
1802
1803@node Invoking Generic Functions
1804@section Invoking Generic Functions
1805
1806When a variable with a generic function definition appears as the first
1807element of a list that is being evaluated, the Guile evaluator tries
1808to apply the generic function to the arguments obtained by evaluating
1809the remaining elements of the list. [ *fixme* How do I put this in a
1810more Schemely and less Lispy way? ]
1811
1812Usually a generic function contains several method definitions, with
1813varying degrees of formal parameter specialization (@pxref{Basic
1814Method Definition,, define-method}). So it is necessary to sort these
1815methods by specificity with respect to the supplied arguments, and then
1816apply the most specific method definition. Less specific methods
1817may be applied subsequently if a method that is being applied calls
1818@code{next-method}.
1819
1820@menu
1821* Determining Which Methods to Apply::
1822* Handling Invocation Errors::
1823@end menu
1824
1825@node Determining Which Methods to Apply
1826@subsection Determining Which Methods to Apply
1827
1828[ *fixme* Sorry - this is the area of GOOPS that I understand least of
1829all, so I'm afraid I have to pass on this section. Would some other
1830kind person consider filling it in? ]
1831
1832@deffn generic apply-generic
1833@deffnx method apply-generic (gf <generic>) args
1834@end deffn
1835
1836@deffn generic compute-applicable-methods
1837@deffnx method compute-applicable-methods (gf <generic>) args
1838@end deffn
1839
1840@deffn generic sort-applicable-methods
1841@deffnx method sort-applicable-methods (gf <generic>) methods args
1842@end deffn
1843
1844@deffn generic method-more-specific?
1845@deffnx method method-more-specific? (m1 <method>) (m2 <method>) args
1846@end deffn
1847
1848@deffn generic apply-method
1849@deffnx method apply-method (gf <generic>) methods build-next args
1850@end deffn
1851
1852@deffn generic apply-methods
1853@deffnx method apply-methods (gf <generic>) (l <list>) args
1854@end deffn
1855
1856@node Handling Invocation Errors
1857@subsection Handling Invocation Errors
1858
1859@deffn generic no-method
1860@deffnx method no-method (gf <generic>) args
1861When an application invokes a generic function, and no methods at all
1862have been defined for that generic function, GOOPS calls the
1863@code{no-method} generic function. The default method calls
1864@code{goops-error} with an appropriate message.
1865@end deffn
1866
1867@deffn generic no-applicable-method
1868@deffnx method no-applicable-method (gf <generic>) args
1869When an application applies a generic function to a set of arguments,
1870and no methods have been defined for those argument types, GOOPS calls
1871the @code{no-applicable-method} generic function. The default method
1872calls @code{goops-error} with an appropriate message.
1873@end deffn
1874
1875@deffn generic no-next-method
1876@deffnx method no-next-method (gf <generic>) args
1877When a generic function method calls @code{(next-method)} to invoke the
1878next less specialized method for that generic function, and no less
1879specialized methods have been defined for the current generic function
1880arguments, GOOPS calls the @code{no-next-method} generic function. The
1881default method calls @code{goops-error} with an appropriate message.
1882@end deffn
1883
1884@node Redefining a Class
1885@section Redefining a Class
1886
1887Suppose that a class @code{<my-class>} is defined using @code{define-class}
1888(@pxref{Basic Class Definition,, define-class}), with slots that have
1889accessor functions, and that an application has created several instances
1890of @code{<my-class>} using @code{make} (@pxref{Basic Instance Creation,,
1891make}). What then happens if @code{<my-class>} is redefined by calling
1892@code{define-class} again?
1893
1894@menu
1895* Default Class Redefinition Behaviour::
1896* Customizing Class Redefinition::
1897@end menu
1898
1899@node Default Class Redefinition Behaviour
1900@subsection Default Class Redefinition Behaviour
1901
1902GOOPS' default answer to this question is as follows.
1903
1904@itemize @bullet
1905@item
1906All existing direct instances of @code{<my-class>} are converted to be
1907instances of the new class. This is achieved by preserving the values
1908of slots that exist in both the old and new definitions, and initializing the
1909values of new slots in the usual way (@pxref{Basic Instance Creation,,
1910make}).
1911
1912@item
1913All existing subclasses of @code{<my-class>} are redefined, as though
1914the @code{define-class} expressions that defined them were re-evaluated
1915following the redefinition of @code{<my-class>}, and the class
1916redefinition process described here is applied recursively to the
1917redefined subclasses.
1918
1919@item
1920Once all of its instances and subclasses have been updated, the class
1921metaobject previously bound to the variable @code{<my-class>} is no
1922longer needed and so can be allowed to be garbage collected.
1923@end itemize
1924
1925To keep things tidy, GOOPS also needs to do a little housekeeping on
1926methods that are associated with the redefined class.
1927
1928@itemize @bullet
1929@item
1930Slot accessor methods for slots in the old definition should be removed
1931from their generic functions. They will be replaced by accessor methods
1932for the slots of the new class definition.
1933
1934@item
1935Any generic function method that uses the old @code{<my-class>} metaobject
1936as one of its formal parameter specializers must be updated to refer to
1937the new @code{<my-class>} metaobject. (Whenever a new generic function
1938method is defined, @code{define-method} adds the method to a list stored
1939in the class metaobject for each class used as a formal parameter
1940specializer, so it is easy to identify all the methods that must be
1941updated when a class is redefined.)
1942@end itemize
1943
1944If this class redefinition strategy strikes you as rather counter-intuitive,
1945bear in mind that it is derived from similar behaviour in other object
1946systems such as CLOS, and that experience in those systems has shown it to be
1947very useful in practice.
1948
1949Also bear in mind that, like most of GOOPS' default behaviour, it can
1950be customized@dots{}
1951
1952@node Customizing Class Redefinition
1953@subsection Customizing Class Redefinition
1954
1955When @code{define-class} notices that a class is being redefined,
1956it constructs the new class metaobject as usual, and then invokes the
1957@code{class-redefinition} generic function with the old and new classes
1958as arguments. Therefore, if the old or new classes have metaclasses
1959other than the default @code{<class>}, class redefinition behaviour can
1960be customized by defining a @code{class-redefinition} method that is
1961specialized for the relevant metaclasses.
1962
1963@deffn generic class-redefinition
1964Handle the class redefinition from @var{old-class} to @var{new-class},
1965and return the new class metaobject that should be bound to the
1966variable specified by @code{define-class}'s first argument.
1967@end deffn
1968
1969@deffn method class-redefinition (old-class <class>) (new-class <class>)
1970Implements GOOPS' default class redefinition behaviour, as described in
1971@ref{Default Class Redefinition Behaviour}. Returns the metaobject
1972for the new class definition.
1973@end deffn
1974
1975An alternative class redefinition strategy could be to leave all
1976existing instances as instances of the old class, but accepting that the
1977old class is now ``nameless'', since its name has been taken over by the
1978new definition. In this strategy, any existing subclasses could also
1979be left as they are, on the understanding that they inherit from a nameless
1980superclass.
1981
1982This strategy is easily implemented in GOOPS, by defining a new metaclass,
1983that will be used as the metaclass for all classes to which the strategy
1984should apply, and then defining a @code{class-redefinition} method that
1985is specialized for this metaclass:
1986
1987@example
1988(define-class <can-be-nameless> (<class>))
1989
1990(define-method (class-redefinition (old <can-be-nameless>) (new <class>))
1991 new)
1992@end example
1993
1994When customization can be as easy as this, aren't you glad that GOOPS
1995implements the far more difficult strategy as its default!
1996
1997Finally, note that, if @code{class-redefinition} itself is not customized,
1998the default @code{class-redefinition} method invokes three further
1999generic functions that could be individually customized:
2000
2001@itemize @bullet
2002@item
2003(remove-class-accessors! @var{old-class})
2004
2005@item
2006(update-direct-method! @var{method} @var{old-class} @var{new-class})
2007
2008@item
2009(update-direct-subclass! @var{subclass} @var{old-class} @var{new-class})
2010@end itemize
2011
2012and the default methods for these generic functions invoke further
2013generic functions, and so on@dots{} The detailed protocol for all of these
2014is described in @ref{MOP Specification}.
2015
2016@node Changing the Class of an Instance
2017@section Changing the Class of an Instance
2018
2019You can change the class of an existing instance by invoking the
2020generic function @code{change-class} with two arguments: the instance
2021and the new class.
2022
2023@deffn generic change-class
2024@end deffn
2025
2026The default method for @code{change-class} decides how to implement the
2027change of class by looking at the slot definitions for the instance's
2028existing class and for the new class. If the new class has slots with
2029the same name as slots in the existing class, the values for those slots
2030are preserved. Slots that are present only in the existing class are
2031discarded. Slots that are present only in the new class are initialized
2032using the corresponding slot definition's init function (@pxref{Classes,,
2033slot-init-function}).
2034
2035@deffn {method} change-class (obj <object>) (new <class>)
2036Modify instance @var{obj} to make it an instance of class @var{new}.
2037
2038The value of each of @var{obj}'s slots is preserved only if a similarly named
2039slot exists in @var{new}; any other slot values are discarded.
2040
2041The slots in @var{new} that do not correspond to any of @var{obj}'s
2042pre-existing slots are initialized according to @var{new}'s slot definitions'
2043init functions.
2044@end deffn
2045
2046Customized change of class behaviour can be implemented by defining
2047@code{change-class} methods that are specialized either by the class
2048of the instances to be modified or by the metaclass of the new class.
2049
2050When a class is redefined (@pxref{Redefining a Class}), and the default
2051class redefinition behaviour is not overridden, GOOPS (eventually)
2052invokes the @code{change-class} generic function for each existing
2053instance of the redefined class.
2054
2055@node Introspection
2056@section Introspection
2057
2058@dfn{Introspection}, also known as @dfn{reflection}, is the name given
2059to the ability to obtain information dynamically about GOOPS metaobjects.
2060It is perhaps best illustrated by considering an object oriented language
2061that does not provide any introspection, namely C++.
2062
2063Nothing in C++ allows a running program to obtain answers to the following
2064types of question:
2065
2066@itemize @bullet
2067@item
2068What are the data members of this object or class?
2069
2070@item
2071What classes does this class inherit from?
2072
2073@item
2074Is this method call virtual or non-virtual?
2075
2076@item
2077If I invoke @code{Employee::adjustHoliday()}, what class contains the
2078@code{adjustHoliday()} method that will be applied?
2079@end itemize
2080
2081In C++, answers to such questions can only be determined by looking at
2082the source code, if you have access to it. GOOPS, on the other hand,
2083includes procedures that allow answers to these questions --- or their
2084GOOPS equivalents --- to be obtained dynamically, at run time.
2085
2086@menu
2087* Classes::
2088* Slots::
2089* Instances::
2090* Generic Functions::
2091* Generic Function Methods::
2092@end menu
2093
2094@node Classes
2095@subsection Classes
2096
2097@deffn {primitive procedure} class-name class
2098Return the name of class @var{class}.
2099This is the value of the @var{class} metaobject's @code{name} slot.
2100@end deffn
2101
2102@deffn {primitive procedure} class-direct-supers class
2103Return a list containing the direct superclasses of @var{class}.
2104This is the value of the @var{class} metaobject's
2105@code{direct-supers} slot.
2106@end deffn
2107
2108@deffn {primitive procedure} class-direct-slots class
2109Return a list containing the slot definitions of the direct slots of
2110@var{class}.
2111This is the value of the @var{class} metaobject's @code{direct-slots}
2112slot.
2113@end deffn
2114
2115@deffn {primitive procedure} class-direct-subclasses class
2116Return a list containing the direct subclasses of @var{class}.
2117This is the value of the @var{class} metaobject's
2118@code{direct-subclasses} slot.
2119@end deffn
2120
2121@deffn {primitive procedure} class-direct-methods class
2122Return a list of all the generic function methods that use @var{class}
2123as a formal parameter specializer.
2124This is the value of the @var{class} metaobject's @code{direct-methods}
2125slot.
2126@end deffn
2127
2128@deffn {primitive procedure} class-precedence-list class
2129Return the class precedence list for class @var{class} (@pxref{Class
2130precedence list}).
2131This is the value of the @var{class} metaobject's @code{cpl} slot.
2132@end deffn
2133
2134@deffn {primitive procedure} class-slots class
2135Return a list containing the slot definitions for all @var{class}'s slots,
2136including any slots that are inherited from superclasses.
2137This is the value of the @var{class} metaobject's @code{slots} slot.
2138@end deffn
2139
2140@deffn {primitive procedure} class-environment class
2141Return the value of @var{class}'s @code{environment} slot.
2142[ *fixme* I don't know what this value is used for. ]
2143@end deffn
2144
2145@deffn procedure class-subclasses class
2146Return a list of all subclasses of @var{class}.
2147@end deffn
2148
2149@deffn procedure class-methods class
2150Return a list of all methods that use @var{class} or a subclass of
2151@var{class} as one of its formal parameter specializers.
2152@end deffn
2153
2154@node Slots
2155@subsection Slots
2156
2157@deffn procedure class-slot-definition class slot-name
2158Return the slot definition for the slot named @var{slot-name} in class
2159@var{class}. @var{slot-name} should be a symbol.
2160@end deffn
2161
2162@deffn procedure slot-definition-name slot-def
2163Extract and return the slot name from @var{slot-def}.
2164@end deffn
2165
2166@deffn procedure slot-definition-options slot-def
2167Extract and return the slot options from @var{slot-def}.
2168@end deffn
2169
2170@deffn procedure slot-definition-allocation slot-def
2171Extract and return the slot allocation option from @var{slot-def}. This
2172is the value of the @code{#:allocation} keyword (@pxref{Slot Options,,
2173allocation}), or @code{#:instance} if the @code{#:allocation} keyword is
2174absent.
2175@end deffn
2176
2177@deffn procedure slot-definition-getter slot-def
2178Extract and return the slot getter option from @var{slot-def}. This is
2179the value of the @code{#:getter} keyword (@pxref{Slot Options,,
2180getter}), or @code{#f} if the @code{#:getter} keyword is absent.
2181@end deffn
2182
2183@deffn procedure slot-definition-setter slot-def
2184Extract and return the slot setter option from @var{slot-def}. This is
2185the value of the @code{#:setter} keyword (@pxref{Slot Options,,
2186setter}), or @code{#f} if the @code{#:setter} keyword is absent.
2187@end deffn
2188
2189@deffn procedure slot-definition-accessor slot-def
2190Extract and return the slot accessor option from @var{slot-def}. This
2191is the value of the @code{#:accessor} keyword (@pxref{Slot Options,,
2192accessor}), or @code{#f} if the @code{#:accessor} keyword is absent.
2193@end deffn
2194
2195@deffn procedure slot-definition-init-value slot-def
2196Extract and return the slot init-value option from @var{slot-def}. This
2197is the value of the @code{#:init-value} keyword (@pxref{Slot Options,,
2198init-value}), or the unbound value if the @code{#:init-value} keyword is
2199absent.
2200@end deffn
2201
2202@deffn procedure slot-definition-init-form slot-def
2203Extract and return the slot init-form option from @var{slot-def}. This
2204is the value of the @code{#:init-form} keyword (@pxref{Slot Options,,
2205init-form}), or the unbound value if the @code{#:init-form} keyword is
2206absent.
2207@end deffn
2208
2209@deffn procedure slot-definition-init-thunk slot-def
2210Extract and return the slot init-thunk option from @var{slot-def}. This
2211is the value of the @code{#:init-thunk} keyword (@pxref{Slot Options,,
2212init-thunk}), or @code{#f} if the @code{#:init-thunk} keyword is absent.
2213@end deffn
2214
2215@deffn procedure slot-definition-init-keyword slot-def
2216Extract and return the slot init-keyword option from @var{slot-def}.
2217This is the value of the @code{#:init-keyword} keyword (@pxref{Slot
2218Options,, init-keyword}), or @code{#f} if the @code{#:init-keyword}
2219keyword is absent.
2220@end deffn
2221
2222@deffn procedure slot-init-function class slot-name
2223Return the initialization function for the slot named @var{slot-name} in
2224class @var{class}. @var{slot-name} should be a symbol.
2225
2226The returned initialization function incorporates the effects of the
2227standard @code{#:init-thunk}, @code{#:init-form} and @code{#:init-value}
2228slot options. These initializations can be overridden by the
2229@code{#:init-keyword} slot option or by a specialized @code{initialize}
2230method, so, in general, the function returned by
2231@code{slot-init-function} may be irrelevant. For a fuller discussion,
2232see @ref{Slot Options,, init-value}.
2233@end deffn
2234
2235@node Instances
2236@subsection Instances
2237
2238@deffn {primitive procedure} class-of value
2239Return the GOOPS class of any Scheme @var{value}.
2240@end deffn
2241
2242@deffn {primitive procedure} instance? object
2243Return @code{#t} if @var{object} is any GOOPS instance, otherwise
2244@code{#f}.
2245@end deffn
2246
2247@deffn procedure is-a? object class
2248Return @code{#t} if @var{object} is an instance of @var{class} or one of
2249its subclasses.
2250@end deffn
2251
2252Implementation notes: @code{is-a?} uses @code{class-of} and
2253@code{class-precedence-list} to obtain the class precedence list for
2254@var{object}.
2255
2256@node Generic Functions
2257@subsection Generic Functions
2258
2259@deffn {primitive procedure} generic-function-name gf
2260Return the name of generic function @var{gf}.
2261@end deffn
2262
2263@deffn {primitive procedure} generic-function-methods gf
2264Return a list of the methods of generic function @var{gf}.
2265This is the value of the @var{gf} metaobject's @code{methods} slot.
2266@end deffn
2267
2268@node Generic Function Methods
2269@subsection Generic Function Methods
2270
2271@deffn {primitive procedure} method-generic-function method
2272Return the generic function that @var{method} belongs to.
2273This is the value of the @var{method} metaobject's
2274@code{generic-function} slot.
2275@end deffn
2276
2277@deffn {primitive procedure} method-specializers method
2278Return a list of @var{method}'s formal parameter specializers .
2279This is the value of the @var{method} metaobject's
2280@code{specializers} slot.
2281@end deffn
2282
2283@deffn {primitive procedure} method-procedure method
2284Return the procedure that implements @var{method}.
2285This is the value of the @var{method} metaobject's
2286@code{procedure} slot.
2287@end deffn
2288
2289@deffn generic method-source
2290@deffnx method method-source (m <method>)
2291Return an expression that prints to show the definition of method
2292@var{m}.
2293
2294@example
2295(define-generic cube)
2296
2297(define-method (cube (n <number>))
2298 (* n n n))
2299
2300(map method-source (generic-function-methods cube))
2301@result{}
2302((method ((n <number>)) (* n n n)))
2303@end example
2304@end deffn
2305
2306@node Miscellaneous Functions
2307@section Miscellaneous Functions
2308
2309@menu
2310* Administrative Functions::
2311* Error Handling::
2312* Object Comparisons::
2313* Cloning Objects::
2314* Write and Display::
2315@end menu
2316
2317@node Administrative Functions
2318@subsection Administration Functions
2319
2320This section describes administrative, non-technical GOOPS functions.
2321
2322@deffn primitive goops-version
2323Return the current GOOPS version as a string, for example ``0.2''.
2324@end deffn
2325
2326@node Error Handling
2327@subsection Error Handling
2328
2329The procedure @code{goops-error} is called to raise an appropriate error
2330by the default methods of the following generic functions:
2331
2332@itemize @bullet
2333@item
2334@code{slot-missing} (@pxref{Handling Slot Access Errors,, slot-missing})
2335
2336@item
2337@code{slot-unbound} (@pxref{Handling Slot Access Errors,, slot-unbound})
2338
2339@item
2340@code{no-method} (@pxref{Handling Invocation Errors,, no-method})
2341
2342@item
2343@code{no-applicable-method} (@pxref{Handling Invocation Errors,,
2344no-applicable-method})
2345
2346@item
2347@code{no-next-method} (@pxref{Handling Invocation Errors,,
2348no-next-method})
2349@end itemize
2350
2351If you customize these functions for particular classes or metaclasses,
2352you may still want to use @code{goops-error} to signal any error
2353conditions that you detect.
2354
2355@deffn procedure goops-error format-string . args
2356Raise an error with key @code{goops-error} and error message constructed
2357from @var{format-string} and @var{args}. Error message formatting is
2358as done by @code{scm-error}.
2359@end deffn
2360
2361@node Object Comparisons
2362@subsection Object Comparisons
2363
2364@deffn generic object-eqv?
2365@deffnx method object-eqv? ((x <top>) (y <top>))
2366@deffnx generic object-equal?
2367@deffnx method object-equal? ((x <top>) (y <top>))
2368Generic functions and default (unspecialized) methods for comparing two
2369GOOPS objects.
2370
2371The default methods always return @code{#f}. Application class authors
2372may wish to define specialized methods for @code{object-eqv?} and
2373@code{object-equal?} that compare instances of the same class for
2374equality in whatever sense is useful to the application.
2375@end deffn
2376
2377@node Cloning Objects
2378@subsection Cloning Objects
2379
2380@deffn generic shallow-clone
2381@deffnx method shallow-clone (self <object>)
2382Return a ``shallow'' clone of @var{self}. The default method makes a
2383shallow clone by allocating a new instance and copying slot values from
2384self to the new instance. Each slot value is copied either as an
2385immediate value or by reference.
2386@end deffn
2387
2388@deffn generic deep-clone
2389@deffnx method deep-clone (self <object>)
2390Return a ``deep'' clone of @var{self}. The default method makes a deep
2391clone by allocating a new instance and copying or cloning slot values
2392from self to the new instance. If a slot value is an instance
2393(satisfies @code{instance?}), it is cloned by calling @code{deep-clone}
2394on that value. Other slot values are copied either as immediate values
2395or by reference.
2396@end deffn
2397
2398@node Write and Display
2399@subsection Write and Display
2400
2401@deffn {primitive generic} write object port
2402@deffnx {primitive generic} display object port
2403When GOOPS is loaded, @code{write} and @code{display} become generic
2404functions with special methods for printing
2405
2406@itemize @bullet
2407@item
2408objects - instances of the class @code{<object>}
2409
2410@item
2411foreign objects - instances of the class @code{<foreign-object>}
2412
2413@item
2414classes - instances of the class @code{<class>}
2415
2416@item
2417generic functions - instances of the class @code{<generic>}
2418
2419@item
2420methods - instances of the class @code{<method>}.
2421@end itemize
2422
2423@code{write} and @code{display} print non-GOOPS values in the same way
2424as the Guile primitive @code{write} and @code{display} functions.
2425@end deffn
2426
2427@node MOP Specification, Tutorial, Reference Manual, Top
2428@chapter MOP Specification
2429
2430For an introduction to metaobjects and the metaobject protocol,
2431see @ref{Metaobjects and the Metaobject Protocol}.
2432
2433The aim of the MOP specification in this chapter is to specify all the
2434customizable generic function invocations that can be made by the standard
2435GOOPS syntax, procedures and methods, and to explain the protocol for
2436customizing such invocations.
2437
2438A generic function invocation is customizable if the types of the arguments
2439to which it is applied are not all determined by the lexical context in
2440which the invocation appears. For example,
2441
2442@itemize @bullet
2443@item
2444the @code{(initialize @var{instance} @var{initargs})} invocation in the
2445default @code{make-instance} method is customizable, because the type of the
2446@code{@var{instance}} argument is determined by the class that was passed to
2447@code{make-instance}.
2448
2449@item
2450the @code{(make <generic> #:name ',name)} invocation in @code{define-generic}
2451is not customizable, because all of its arguments have lexically determined
2452types.
2453@end itemize
2454
2455When using this rule to decide whether a given generic function invocation
2456is customizable, we ignore arguments that are expected to be handled in
2457method definitions as a single ``rest'' list argument.
2458
2459For each customizable generic function invocation, the @dfn{invocation
2460protocol} is explained by specifying
2461
2462@itemize @bullet
2463@item
2464what, conceptually, the applied method is intended to do
2465
2466@item
2467what assumptions, if any, the caller makes about the applied method's side
2468effects
2469
2470@item
2471what the caller expects to get as the applied method's return value.
2472@end itemize
2473
2474@menu
2475* Class Definition::
2476* Instance Creation::
2477* Class Redefinition::
2478* Method Definition::
2479* Generic Function Invocation::
2480@end menu
2481
2482@node Class Definition
2483@section Class Definition
2484
2485@code{define-class} (syntax)
2486
2487@itemize @bullet
2488@item
2489@code{class} (syntax)
2490
2491@itemize @bullet
2492@item
2493@code{make-class} (procedure)
2494
2495@itemize @bullet
2496@item
2497@code{make @var{metaclass} @dots{}} (generic)
2498
2499@var{metaclass} is the metaclass of the class being defined, either
2500taken from the @code{#:metaclass} class option or computed by
2501@code{ensure-metaclass}. The applied method must create and return the
2502fully initialized class metaobject for the new class definition.
2503@end itemize
2504
2505@end itemize
2506
2507@item
2508@code{class-redefinition @var{old-class} @var{new-class}} (generic)
2509
2510@code{define-class} calls @code{class-redefinition} if the variable
2511specified by its first argument already held a GOOPS class definition.
2512@var{old-class} and @var{new-class} are the old and new class metaobjects.
2513The applied method should perform whatever is necessary to handle the
2514redefinition, and should return the class metaobject that is to be bound
2515to @code{define-class}'s variable. The default class redefinition
2516protocol is described in @ref{Class Redefinition}.
2517@end itemize
2518
2519The @code{(make @var{metaclass} @dots{})} invocation above will create
2520an class metaobject with metaclass @var{metaclass}. By default, this
2521metaobject will be initialized by the @code{initialize} method that is
2522specialized for instances of type @code{<class>}.
2523
2524@code{initialize <class> @var{initargs}} (method)
2525
2526@itemize @bullet
2527@item
2528@code{compute-cpl @var{class}} (generic)
2529
2530The applied method should compute and return the class precedence list
2531for @var{class} as a list of class metaobjects. When @code{compute-cpl}
2532is called, the following @var{class} metaobject slots have all been
2533initialized: @code{name}, @code{direct-supers}, @code{direct-slots},
2534@code{direct-subclasses} (empty), @code{direct-methods}. The value
2535returned by @code{compute-cpl} will be stored in the @code{cpl} slot.
2536
2537@item
2538@code{compute-slots @var{class}} (generic)
2539
2540The applied method should compute and return the slots (union of direct
2541and inherited) for @var{class} as a list of slot definitions. When
2542@code{compute-slots} is called, all the @var{class} metaobject slots
2543mentioned for @code{compute-cpl} have been initialized, plus the
2544following: @code{cpl}, @code{redefined} (@code{#f}), @code{environment}.
2545The value returned by @code{compute-slots} will be stored in the
2546@code{slots} slot.
2547
2548@item
2549@code{compute-get-n-set @var{class} @var{slot-def}} (generic)
2550
2551@code{initialize} calls @code{compute-get-n-set} for each slot computed
2552by @code{compute-slots}. The applied method should compute and return a
2553pair of closures that, respectively, get and set the value of the specified
2554slot. The get closure should have arity 1 and expect a single argument
2555that is the instance whose slot value is to be retrieved. The set closure
2556should have arity 2 and expect two arguments, where the first argument is
2557the instance whose slot value is to be set and the second argument is the
2558new value for that slot. The closures should be returned in a two element
2559list: @code{(list @var{get} @var{set})}.
2560
2561The closures returned by @code{compute-get-n-set} are stored as part of
2562the value of the @var{class} metaobject's @code{getters-n-setters} slot.
2563Specifically, the value of this slot is a list with the same number of
2564elements as there are slots in the class, and each element looks either like
2565
2566@example
2567@code{(@var{slot-name-symbol} @var{init-function} . @var{index})}
2568@end example
2569
2570or like
2571
2572@example
2573@code{(@var{slot-name-symbol} @var{init-function} @var{get} @var{set})}
2574@end example
2575
2576Where the get and set closures are replaced by @var{index}, the slot is
2577an instance slot and @var{index} is the slot's index in the underlying
2578structure: GOOPS knows how to get and set the value of such slots and so
2579does not need specially constructed get and set closures. Otherwise,
2580@var{get} and @var{set} are the closures returned by @code{compute-get-n-set}.
2581
2582The structure of the @code{getters-n-setters} slot value is important when
2583understanding the next customizable generic functions that @code{initialize}
2584calls@dots{}
2585
2586@item
2587@code{compute-getter-method @var{class} @var{gns}} (generic)
2588
2589@code{initialize} calls @code{compute-getter-method} for each of the class's
2590slots (as determined by @code{compute-slots}) that includes a
2591@code{#:getter} or @code{#:accessor} slot option. @var{gns} is the
2592element of the @var{class} metaobject's @code{getters-n-setters} slot that
2593specifies how the slot in question is referenced and set, as described
2594above under @code{compute-get-n-set}. The applied method should create
2595and return a method that is specialized for instances of type @var{class}
2596and uses the get closure to retrieve the slot's value. [ *fixme Need
2597to insert something here about checking that the value is not unbound. ]
2598@code{initialize} uses @code{add-method!} to add the returned method to
2599the generic function named by the slot definition's @code{#:getter} or
2600@code{#:accessor} option.
2601
2602@item
2603@code{compute-setter-method @var{class} @var{gns}} (generic)
2604
2605@code{compute-setter-method} is invoked with the same arguments as
2606@code{compute-getter-method}, for each of the class's slots that includes
2607a @code{#:setter} or @code{#:accessor} slot option. The applied method
2608should create and return a method that is specialized for instances of
2609type @var{class} and uses the set closure to set the slot's value.
2610@code{initialize} then uses @code{add-method!} to add the returned method
2611to the generic function named by the slot definition's @code{#:setter}
2612or @code{#:accessor} option.
2613@end itemize
2614
2615@node Instance Creation
2616@section Instance Creation
2617
2618@code{make <class> . @var{initargs}} (method)
2619
2620@itemize @bullet
2621@item
2622@code{allocate-instance @var{class} @var{initargs}} (generic)
2623
2624The applied @code{allocate-instance} method should allocate storage for
2625a new instance of class @var{class} and return the uninitialized instance.
2626
2627@item
2628@code{initialize @var{instance} @var{initargs}} (generic)
2629
2630@var{instance} is the uninitialized instance returned by
2631@code{allocate-instance}. The applied method should initialize the new
2632instance in whatever sense is appropriate for its class. The method's
2633return value is ignored.
2634@end itemize
2635
2636@node Class Redefinition
2637@section Class Redefinition
2638
2639The default @code{class-redefinition} method, specialized for classes
2640with the default metaclass @code{<class>}, has the following internal
2641protocol.
2642
2643[ *fixme* I'm not sure that I understand this sufficiently to explain
2644it. Also, the internals of the default class redefinition method are
2645extremely implementation-specific, and I'm not sure that there is that
2646much point trying to describe the internal protocol such that it could
2647be customized without going to look at the source code. ]
2648
2649@code{class-redefinition @var{(old <class>)} @var{(new <class>)}}
2650(method)
2651
2652@itemize @bullet
2653@item
2654@code{remove-class-accessors! @var{old}} (generic)
2655
2656@item
2657@code{update-direct-method! @var{method} @var{old} @var{new}} (generic)
2658
2659@item
2660@code{update-direct-subclass! @var{subclass} @var{old} @var{new}} (generic)
2661@end itemize
2662
2663The default @code{update-direct-subclass!} method invokes
2664@code{class-redefinition} recursively to handle the redefinition of the
2665subclass.
2666
2667When a class is redefined, any existing instance of the redefined class
2668will be modified for the new class definition before the next time that
2669any of the instance's slot is referenced or set. GOOPS modifies each
2670instance by calling the generic function @code{change-class}. [ *fixme*
2671Actually it sometimes calls @code{change-class} and sometimes
2672@code{change-object-class}, and I don't understand why. ]
2673
2674The default @code{change-class} method copies slot values from the old
2675to the modified instance, and initializes new slots, as described in
2676@ref{Changing the Class of an Instance}. After doing so, it makes a
2677generic function invocation that can be used to customize the instance
2678update algorithm.
2679
2680@code{change-class @var{(old-instance <object>)} @var{(new <class>)}} (method)
2681
2682@itemize @bullet
2683@item
2684@code{update-instance-for-different-class @var{old-instance} @var{new-instance}} (generic)
2685
2686@code{change-class} invokes @code{update-instance-for-different-class}
2687as the last thing that it does before returning. The applied method can
2688make any further adjustments to @var{new-instance} that are required to
2689complete or modify the change of class. The return value from the
2690applied method is ignored.
2691
2692The default @code{update-instance-for-different-class} method does
2693nothing.
2694@end itemize
2695
2696@node Method Definition
2697@section Method Definition
2698
2699@code{define-method} (syntax)
2700
2701@itemize @bullet
2702@item
2703@code{add-method! @var{target} @var{method}} (generic)
2704
2705@code{define-method} invokes the @code{add-method!} generic function to
2706handle adding the new method to a variety of possible targets. GOOPS
2707includes methods to handle @var{target} as
2708
2709@itemize @bullet
2710@item
2711a generic function (the most common case)
2712
2713@item
2714a procedure
2715
2716@item
2717a primitive generic (@pxref{Extending Guiles Primitives})
2718@end itemize
2719
2720By defining further methods for @code{add-method!}, you can
2721theoretically handle adding methods to further types of target.
2722@end itemize
2723
2724@node Generic Function Invocation
2725@section Generic Function Invocation
2726
2727[ *fixme* Description required here. ]
2728
2729@code{apply-generic}
2730
2731@itemize @bullet
2732@item
2733@code{no-method}
2734
2735@item
2736@code{compute-applicable-methods}
2737
2738@item
2739@code{sort-applicable-methods}
2740
2741@item
2742@code{apply-methods}
2743
2744@item
2745@code{no-applicable-method}
2746@end itemize
2747
2748@code{sort-applicable-methods}
2749
2750@itemize @bullet
2751@item
2752@code{method-more-specific?}
2753@end itemize
2754
2755@code{apply-methods}
2756
2757@itemize @bullet
2758@item
2759@code{apply-method}
2760@end itemize
2761
2762@code{next-method}
2763
2764@itemize @bullet
2765@item
2766@code{no-next-method}
2767@end itemize
2768
2769@node Tutorial, Index, MOP Specification, Top
2770@chapter Tutorial
2771@include goops-tutorial.texi
2772
2773@node Index, Concept Index, Tutorial, Top
2774@chapter Index
2775@page
2776@node Concept Index, Function and Variable Index, Index, Top
2777@unnumberedsec Concept Index
2778
2779@printindex cp
2780
2781@node Function and Variable Index, , Concept Index, Top
2782@unnumberedsec Function and Variable Index
2783
2784@printindex fn
2785
2786@summarycontents
2787@contents
2788@bye