Dear Allin,
Thank you for comprehensive
answer.
I have experience in learning some soft
by experiments, so I hope to be useful
in finding undocumented hacks to
be excluded

P.S. Sorry for inaccurate line:
> eval isnull(varname(somelist)
This works:
nulldata 1
list nlist = null
z = isnull(varname(nlist))
z

Another hack or legal?


27 жовтня 2015, 22:25:12, від "Allin Cottrell" <cottrell@wfu.edu>:

On Tue, 27 Oct 2015, oleg_komashko@ukr.net wrote:

> Dear all, There are several ways to check whether a list is empty, e.g.
> eval isnull(varname(somelist)
> eval somelist=null
> eval nelem(list)
> 1) Which way is the most efficient/ recommended ?

If you want to check whether a variable of type list has 0 members 
the only sane way is the third, using nelem(). The first "eval" is
invalid syntax and the second, if it works, is some sort of 
undocumented hack.

> Also, the behavior of null keyword is different with lists and 
> strings, for example

> somelist = null 
> is evaluated but
> eval somestring = null
> outputs
> Data types not conformable for operation

Like I said, an undocumented hack.

> 2) Is there a compact text on null keyword?

No. That's the whole problem here. We (well, I take most of the 
responsibility) did not properly think through what precise meaning 
we wanted to attach to "null", across the various contexts in which 
we have allowed it to occur.

> I can imagine the following way to use isnull(): Suppose, I want 
> to write a function which creates new variables with automated 
> names. isnull() could be used for checking duplicated names.

Yes, that's true. As it stands, isnull() returns 1 if and only if 
there is no object with the name given as an argument; so it could 
be used to avoid collision of names.

> 3) What are main uses of isnull()

The main intended use of isnull() is for writers of functions. 
Suppose you have written a function which has a parameter specified 
like

matrix *m[null]

or

bundle *b[null]

that is, a "pointerized" variable with a default of "null", so that 
the caller is OK with skipping the argument, or giving a dummy 
argument of "null". Now you want to know if you actually got a 
existing variable as an argument: isnull() will do the job. However, 
it won't do the job for list arguments with a "null" default, 
because (as things stand) gretl will manufacture an empty list as a 
pseudo-argument.

Allin
_______________________________________________
Gretl-devel mailing list
Gretl-devel@lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-devel