Initializers

The make function handles much of the drudgery of object construction. It processes keywords and initializes slots. Programmers may, however, customize this process by adding methods to the generic function initialize. For example, if vehicle serial numbers must be at least seven digits:

define method initialize(v :: <vehicle>, #all-keys) // accepts all keywords
	next-method( );
	if (v.serial-number < 1000000)
		error("Bad serial number!");
	end if;
end method;
      

Initialize methods get called after regular slot initialization. They typically perform error checking or calculate values for unusual slots. Initialize methods must accept all keywords using #all-keys.

It's possible to access the values of slot keywords from initialize methods, and even to specify additional keywords in the class declaration. See the Dylan Reference Manual for further details.