Am 30.07.2011 19:02, schrieb Allin Cottrell:
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.
That's something *I* don't understand. NA is not a real-valued number
either, I don't see why this is any different from allowing ints or
booleans to take that special value. As you say, a default of NA for
generic scalars just means "don't care". Why can't NA also mean
"don't
care" for a boolean (or int) argument?
I suspect that internally you map NA to NaN which is handled in the
underlying floating-point logic. And that would perhaps not be so easy
to achieve with internal integers. If that is so, it's a valid technical
reason, but not one that concerns the user side and the way it
necessarily should be done if it were easy, IMHO.
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.
Sure; also one could work around it by employing a gretl scalar to be
able to set it to NA, even if actually valid values are only
non-negative ints (which would then have to be checked by the function
writer). Actually I guess this is what will happen which would be
slightly counterproductive.
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.
Your work on filling that gap is much appreciated! But I still argue
that the same things apply to ints and booleans; your argument above
rests on the special case where negative ints are not meaningful per se,
but that is an ad hoc assumption. In general any integer value could be
meaningful, and thus in general you cannot designate any particular
value as conveying the "don't care" signal. And the same goes (even more
forcefully) for the two possible values of booleans.
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.
Right (in the British sense :-)
cheers,
sven