7 Additional Extensions to Common Lisp

7.7 CLOS extensions

The following are extensions to the Common Lisp Object System.

compile-all-dispatch-code Macro

Syntax:compile-all-dispatch-code

The macrocompile-all-dispatch-code compiles dispatch code and makes it available at run-time to generic functions used by an application that has no compiler.

Code that dispatches from generic functions to their methods is known as dispatch code. It selects methods according to the classes of their arguments. The dispatch code is determined by the number and kinds of methods that the generic function has.

Before calling the correct methods, dispatch code must be installed in a generic function. The most common forms of generic function arguments and methods have dispatch codes already precompiled in CLOS. If no dispatch code fits a generic function, Lisp tries to compile dispatch code for it. Occasionally, the system must compile the dispatch code used by a generic function at run-time, since it cannot predict what methods a generic function will have when it is called. This operation can be expensive, especially if it occurs every time a new method is defined. For this reason, dispatch code is not installed in a generic function until it is called the first time after it is defined or until a change is made in the methods. If no precompiled dispatch code is available and there is no compiler available, the dispatch code is run by a slower technique.

The macrocompile-all-dispatch-code makes dispatch code available to be compiled into a file. Loading that file makes dispatch code available without any further need to compile.

Note: A CLOS application will run without a compiler or precompiled dispatch code, but the dispatch code that would have been compiled at run-time is slower.

The difference between the macrocompile-all-dispatch-code and the functionprecompile-generic-functions is thatprecompile-generic-functions compiles dispatch code directly into the running Lisp, whilecompile-all-dispatch-code puts the compiled dispatch code into a separate file that can then (for the HP, Solaris, and SunOS platforms) be loaded into a compilerless application. See Appendix A, "The Application Environment" in The User's Guide for more information about compilerless applications.

To create and use a file containing compiled dispatch code, use the following steps:

;;; Add an IN-PACKAGE because you need one in
;;; every file you compile. 
(in-package "CLOS") 

;;; This call expands into the necessary dispatch code. (compile-all-dispatch-code)

See Also: precompile-generic-functions

list-all-classes Function

Syntax:list-all-classes &optional return-names

The functionlist-all-classes returns a list of all named class objects.

If the optional return-names argument has a non-nil value, the function returns a list of the names of all named classes, instead of the class objects themselves. The default value of this argument isnil.

precompile-generic-functions Function

Syntax:precompile-generic-functions

Occasionally generic function dispatch functions and effective method functions need to be compiled when a generic function is invoked. For optimization purposes, the effective method and generic function dispatch units depend upon the particular argument spectrum of the generic function and on the number and kinds of methods defined upon it. Not all conceivable effective method and generic function dispatch patterns exist in the initial system; many have to be generated and compiled at run-time.

When a method is compiled, it is impossible to know what other methods might be defined at some future time; thus, the compiler does not automatically generate any additional compiled code units for generic functions. The functionprecompile-generic-functions compiles all the code needed at run-time by all currently defined generic functions.

Once you have invoked this function, generic function and method invocation will not cause further compilation to occur unless new methods, generic functions, or classes are defined.

You can call this function after loading a Common Lisp Object System application into a Lisp image to precompile any uncompiled code.

You cannot use this function if the compiler is not present in the image.

See Also: compile-all-dispatch-code

trace-method Function

untrace-method Function

Syntax:trace-method &optional method-spec ({keyword form}*)

Syntax:untrace-method &optional method-spec

method-spec ::= method-object |(generic-function-name {qualifier}* ({specializer-name}*))

The functiontrace-method allows you to trace the execution of a method and to perform certain actions when the method is called or when it returns. If you calltrace-method with no arguments, a list of all currently traced methods is returned.

The functionuntrace-method disables tracing for a method. If you calluntrace-method with no arguments, tracing is turned off for all methods currently being traced.

The generic-function-name argument of the optional method-spec argument is either a symbol or a list of the form(setf symbol).

The optional (keyword form) arguments totrace-method are treated like (keyword form) arguments to the macrotrace. See the reference page fortrace in The User's Guide for information about these arguments.

> (trace-method '(frobulate :before (food))) 
#<Standard-Method FROBULATE :BEFORE (FOOD)>

> (frobulate d) 1 Enter #:|(FROBULATE :BEFORE (FOOD))| #<Food #XB4F183> 1 Exit #:|(FROBULATE :BEFORE (FOOD))| AUTO NIL

> (untrace-method) #<Standard-Method FROBULATE :BEFORE (FOOD)>

See Also: trace-method, untrace-method;monitor-method (in The User's Guide)

undefmethod Function

Syntax:undefmethod method-spec

method-spec ::= method-object |(generic-function-name {qualifier}* ({specializer-name}*))

The functionundefmethod removes a method definition from the system.

The generic-function-name argument of the method-spec argument is either a symbol or a list of the form(setf symbol).

If there is no such method object,undefmethod returnsnil. If a generic function does not exist for the specified method-spec, an error is signaled.


The Advanced User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker