On Mon, 8 Jan 2018, Sven Schreiber wrote:
Am 08.01.2018 um 10:21 schrieb Schaff, Frederik:
>
> Hi there, I pose this question & suggestion here instead the
> users list, I hope that is fine in this context.
Yes, perfect.
>
> It is currently not possible to use „null“ as a default argument
> for scalar variables in function headers. It is, however,
> possible to use „NA“. My question: Is there a save procedure to
> use “!isnan(variable)” similar to “exists(matrix)” for function
> headers? Currently, this seems not possible (or I am making a
> mistake). E.g.:
>
You're making a mistake :-)
NaN is not the same as NA. You can dig up a bunch of discussions about
gretl's creation of NAs in the lists in the past.
But the point for you is that you probably want to use missing() or ok().
Apart from that, I would usually recommend against a NA default
value for a scalar. Instead use a "sensible" default that really
is something that would be chosen often. Or use some code value;
for example if a strictly positive number is expected, the default
value 0 can be taken as an equivalent signal to NA. Or of only
non-negative numbers make sense, use -1 to signal some special
meaning. And so on.
I agree with Sven, but at a pinch it's OK to give NA as the default
value for a scalar argument, in which case (as Sven says) the test
is done via missing() or its converse, ok().
> And then one other thing. In Python one can conveniently pass
> optional arguments via “argument_label=argument_value”, without
> having to care about the sorting/completeness of the argument
> list. If such a thing was possible in hansl, that would be very
> convenient!
[...]
[I]t would be nice to have, but I'm afraid that it would
represent
a major internal reorganization effort. (Allin will probably
comment on that when he's back online.)
Yes, it would be quite a major change.
But one (somewhat relevant) point is that it's now OK (in recent
git) to skip one or more optional arguments altogether, provided one
inserts commas to preserve the argument count where necessary.
(Commas are not required if only trailing optional arguments are
skipped.)
For example, if a function foo() takes three arguments, with the
last two optional, and a caller wishes to supply only arguments 1
and 3, then
foo(x,,z)
is an acceptable call.
Allin