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