Keyword Arguments

Functions may accept keyword arguments, extra parameters which are identified by a label rather than by their postion in the argument list. Keyword arguments are often used in a fashion similar to default parameter values in C++. For example, the following hypothetical method might print records to an output device:

define method print-records(records :: <collection>,
	#key init-codes = "", lines-per-page = 66) => ();

	// ...print the records
end method;

This method could be invoked in one of several ways. The first specifies no keyword arguments, and the latter two specify some combination of them. Note that order of keyword arguments doesn't matter.

print-records(recs, lines-per-page: 65);
print-records(recs, lines-per-page: 120, init-codes: "***42\n");

Programmers have quite a bit of flexibility in specifying keyword arguments. They may optionally omit the default value for a keyword (in which case #f is used). Default value specifiers may actually be function calls themselves, and may rely on regular parameters already being in scope. Variable names may be different from keyword names, a handy tool for preventing name conflicts.

For more information on keyword arguments, especially their use with generic functions, see the Dylan Reference Manual .