On Fri, 7 Apr 2017, Sven Schreiber wrote:
Hi again,
so I've revisited the whole story about default function arguments. Some time
ago it was decided that for 'string' and 'matrix' types it is possible to
mark them as optional by appending '[null]', without using pointers (which is
still possible).
The same trick doesn't work for the array types 'strings' or
'matrices' (or
'bundles', for that matter). Is there a specific reason?
That nobody has requested it to date?
To be clear, this does NOT work:
<hansl-fail>
function void ch2( strings ss[null])
if exists(ss)
print "exists"
elif !isnull(ss)
print "isn't null"
endif
end function
ch2()
</hansl-fail>
It would sometimes come in handy for optional array arguments.
Yes, except that the conditionality above is funny ;-) If x doesn't
exist, it's surely not going to be non-null!
OK, now (in git, not shapshots yet) I've enabled the "null" default
for all types that might reasonably be considered "pointery": so not
just arrays but also bundles and series.
If you (as a function writer) choose to give a "null" default for
any of these parameter types, you need to be ready to use exists()
to check whether the caller actually gave you anything.
As the caller of such a function you should be able to give "null"
(without the quotes), or just leave an empty argument slot, for
any arguments specified in this way.
Just to be clear, "null" is never acceptable -- either as a default
value when you're writing a function or as a dummy argument when
you're calling one -- for the scalar types (scalar, int, bool).
Allin