On Fri, 22 Jul 2011, Sven Schreiber wrote:
Am 21.07.2011 22:48, schrieb Allin Cottrell:
> Two new things in CVS that I think should be
> uncontroversial, but please let me know if any
> breakage results:
>
> * Up till now it has been impossible to give a scalar
> parameter to a user-defined function a default value of
> NA. This is partly because NA was used as the internal
> representation for "no value set". However, it seemed
> to me that in some cases it may be useful to set a
> default of NA for a trailing parameter, meaning that
> if the user omits a value for that parameter, it
> should then be ignored (not used) within the function.
>
> This is now possible, but note, only for parameters
> of type "scalar", not "bool" or "int".
It's nice to be able to omit parameters in function calls when they are
redundant. However, this would seem to apply to all types of arguments.
I somehow would prefer a coherent solution to this instead of a
case-by-case approach (which is hard to remember).
I'm not sure what you have in mind. The way I see it, the
suitable form of a "don't care" default for a given trailing
parameter depends on its type. "null" is fine for pointer
types but otherwise does not make sense (at least for people
who tend to think in C). For booleans, the only sane default
would be 1 or 0; and so on.
In the end, it's up to the function writer to handle the
arguments received, and the writer has the discretion to set a
default that will be interpreted inside the function as "don't
bother with this", where applicable. For example, with an
optional parameter whose valid values are non-negative ints, a
default of -1 could be used.
I was just trying to fill a gap, in that without the ability
to set NA as the default for a scalar parameter whose valid
values (in principle) span the real line, there was no clean
way to do what I wanted, namely set a default that could be
read as "Not applicable" inside my function.
I should perhaps state briefly for the record how the optional
argument business goes. When call to a user function is set
up, we check the arguments supplied against the parameter
list, for type and number. If the number of arguments is short
of the number of parameters, we see if all the trailing
parameters have default values recorded. If so, the arguments
are set to their defaults, otherwise an error is flagged.
Allin