On Wed, 20 Dec 2017, Sven Schreiber wrote:
The thing is that lists are special, and therefore you shouldn't
use exists()
on them *when checking for a function argument*, only nelem(). This is an
exception, and as you saw before nelem() on another function argument type
which is 'null' wouldn't work. There was a thread about these things about a
year ago.
So, the bottom line for checking 'null' default values for function
arguments:
- almost always use exists() first
- but for lists use (only) nelem() directly
- [for lists that are not function args you should be able to use exists() as
well]
Again, I completely understand the confusion, this is the result of
some path dependency in the past.
Yes indeed. The "list" type has been around for a long time and when
the business of a "null" default for function arguments first came up
we decided that if the caller did not provide an argument, the
function would nonetheless get an empty list under the name of the
parameter. Hence the behavior of exists() in this case.
Subsequently we changed our mind about the most desirable treatment of
the "null" default, and for matrix, bundle, array and series there's
no special construction of an empty object as pseudo-argument. But for
reasons of backward compatibility we didn't go back and change the
behavior for list arguments.
Maybe it's time to reconsider: how disruptive would it be to change
the behavior with list arguments to match that with other objects?
Whichever way we decide to go, I agree with Sven that we should
update/clarify the documentation.
Allin