Hi,
we repeatedly tried to tackle the problem that a gretl list as a
function argument with a null default value is special;
exists(mylistarg) will return 1 even when mylistarg was left at the
default 'null', for historical reasons.
Just now we again had a case on the users list that this situation
causes confusion.
What about this possible solution:
Let's introduce a special variant of exists() using a new optional
string arg "listarg" as follows: The call
exists(mylistarg, "listarg")
would be internally rerouted and equivalent to the expression
'nelem(mylistarg) > 0'. Example:
<hansl>
function void listex( list L[null])
eval exists(L)
eval nelem(L)
eval exists(L, "listarg")
end function
listex()
# would print out:
# 1 -- for exists(L)
# 0 -- for nelem(L)
# 0 -- for the new exists(L, "listarg")
list LL = foo bar
listex(LL)
# would print out:
# 1
# 2
# 1
# And usage without a function arg:
exists(LL, "listarg") # not inside a function, might yield an error
# ... but treating this just as exists(LL) is also a possibility
</hansl>
Thoughts?
thanks,
sven
Show replies by date