Syntax:
defresource name parameters &key constructor initializer deinitializer matcher initial-copies => name
Arguments and Values:
name---a symbol.
parameters---an ordinary lambda-list.
constructor---an expression. This argument is required.
initializer---an expression.
deinitializer---an expression.
matcher---an expression.
initial-copies---an integer or NIL. The
default is NIL
Description:
Defresource defines a resource named name. Parameters is a lambda-list giving names and default values (for optional and keyword parameters) of parameters to an object of this type.
Constructor is an expression that is responsible for creating an object, and is called when someone tries to allocate an object from the resource and no suitable free objects exist. The constructor form can access the parameters as variables.
Initializer is an expression that is used to initialize an object gotten from the resource. It can access the parameters as variables, and also has access to a variable called name, which is the object to be initialized. The initializer is called both on newly created objects and objects that are being reused.
Deinitializer is an expression that is used to deinitialize an object when it is about to be returned to the resource. It can access the parameters as variables, and also has access to a variable called name, which is the object to be deinitialized. It is called whenever an object is deallocated back to the resource, but is not called by clear-resource. Deinitializers are typically used to clear references to other objects.
Matcher is an expression that ensures that an object in the resource "matches" the specified parameters, which it can access as variables. In addition, the matcher also has access to a variable called name, which is the object in the resource being matched against. If no matcher is supplied, the system remembers the value for the parameters (including optional ones that defaulted) that were used to construct the object, and assumes that it matches those particular values for all time. This comparison is done with equal. The matcher should return true if there is a match, otherwise it should return false.
Initial-copies is used to specify the number of objects that
should be initially put into the resource. NIL is
equivalent to 0. If initial copes are made and there are parameters,
all the parameters must be optional; in this case, the initial copies
have the default values of the parameters.
Side Effects: Redefines any existing resource of the same name.
Affected By: None.
Exceptional Situations: None.
See Also:
allocate-resource, clear-resource, deallocate-resource, map-resource, using-resource.
Notes:
After redefining a resource, it may be necessary to recompile any previously compiled references to that resource, whether the reference is through the macro using-resource, or a function such as allocate-resource.