[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Optional and Default Parameters
Are there any plans to include something on the order of Zetalisp
&Optional field in the parameter list for functions? ...
It's not hard to build that on top of T, although if you add the whole
bunch of &-keywords, it gets very messy. I use the following notation
for specifying optional parameters that don't all have to come at the
end:
(DEFINE-OPT (name . specs) (defaults) . code)
where each spec is either a symbol, signifying a required parameter,
or a list containing optional parameters. The depth of nesting
indicates the order of preference; obviously, no two optional parameters
should be nested at the same depth. Example:
(DEFINE-OPT (SET-DRAW-COLOR (BITMAP (COLOR-MAP)) NEW-COLOR)
((CURRENT-BITMAP)
(CURRENT-COLOR-MAP))
(SET (ELT COLOR-MAP (DRAW-COLOR-INDEX BITMAP)) NEW-COLOR))
This would be documented as
(SET-DRAW-COLOR {bitmap {color-map}} color) -> color
This routine sets the color used for drawing lines on bitmap.
Bitmap defaults to (CURRENT-BITMAP) and color-map defaults to
(CURRENT-COLOR-MAP).
In other words, if there is only one parameter, it must be the color.
If there are two, they're assumed to be the bitmap and the color,
because the bitmap parameter is not as deeply nested as the color-map
parameter. The defaults are given in left-to-right order, regardless
of the nesting depth of the optional parameters for which they are
the defaults. Defaults are closed outside the procedure definition.
The code to do this is pretty simple. (See <A.PEARL.MEEHAN>LEXPR.T
on the Research 20.) Lots of variations are possible.
-------