|
|
Wasn't it Alan Walkington who wrote:
>In a macro, is it possible to define default values for parameters, so they
>can be skipped during instantiation?
>
>#macro Laser (Color = 'Red')
> body here
>#end
>
>so that calling:
>
>Laser() would produce a Red laser,
>Laser(Green) would produce a Green laser, and so forth?
>This doesn't work, of course, but some other way?
One way is to allow the variables to be declared outside the macro call,
and use #ifdef/#ifndef to see if they are declared. Something like this:
#macro Laser
#ifndef (Laser_Colour)
#local Laser_Colour = Red;
#end
body here
#end
or
#macro Laser
#ifndef (Laser_Colour)
#declare Laser_Colour = Red;
#end
body here
#undef Laser_Colour
#end
In the second version, the macro undefines the copy of Laser_Colour that
exists in the calling code, so that the next laser will default back to
Red, whereas in the first version the laser defaults to the previously
selected colour.
--
Mike Williams
Gentleman of Leisure
Post a reply to this message
|
|