On Sat, 26 Jul 2008, Riccardo (Jack) Lucchetti wrote:
On Sat, 26 Jul 2008, Allin Cottrell wrote:
> As for string arguments, the lack of a facility for setting a null
> default was an oversight, now fixed in CVS/snapshot. The syntax
> is now the same as for lists, e.g.,
Nice. How would you like to generalise this mechanism, giving
every type we have a default value? We already have null for a
few cases (pointers, lists and now strings): NA comes to mind
for scalars and {} for matrices. For series, I wouldn't know
(maybe a string of NAs? const? 0?). This way, every parameter
becomes optional.
The way I see it, it's up to the writer of a function to specify
if an argument is optional, by supplying a default value for the
parameter in question. At present we support that (via "null")
for pointer parameters, lists and strings, as you say; we also
support numerical default values for scalar parameters.
That leaves (non-pointer) series and matrix parameters; at present
there's no mechanism for giving them a default value. (Although a
function writer can, of course, make these into pointer arguments
and give them a null default.) For series, I suppose we could
support a constant default, as in
function myfun (series y[1], ...)
which would make y a full-length series that's all 1s. Matrices
would be trickier, though I guess we could support "null" for
them.
Allin.