> It is currently not possible to evaluate if an array of matrices
is
> equal to null or not.
I think you want either
exists(foo)
to check whether or not there's any object named "foo", or, if you're
sure
that foo exists but want to check if it actually contains any
members/elements:
nelem(foo) != 0
The latter check will work for objects of type matrix, list, array and bundle
(that is, all gretl types that can exist yet be empty).
The formulation "foo == null" is not supported in hansl.
Allin
Ah, I had exactly this '!=' formulation before. Now, you point out that it does
not work for matrices, which explains why I had trouble in the first place. However,
'matrices x = null' is valid, so it might be good to have it? (btw
"a==b" did work the same as "!a!=b" for me).
There is an issue with 'exists' and the scope (function vs. script/global). It
seems to be the case that exists checks, at least for lists, on the global scope. Run the
following short test script, to see what I mean. At any rate, this script is also a
workaround for me, now.
Perhaps some specific function for 'function' scope, to test whether a parameter
is passed or not, would be nice? something like 'passed(par)' which evaluates to
1/true if a parameter was passed and to 0/false if not (i.e. 'null' was passed),
valid for all kind of possible data that hansl supports.
<hansl>
function void test(matrices MS[null], list ls[null])
if !exists(MS)
print "MS is not defined"
else
print "MS defined"
endif
if !exists(ls) #problem: if ls exists on higher level...
print "List not defined"
else
print "List defined"
if !(ls!=null)
print "but its empty (on this scope)"
endif
if ls==null
print "also '==' check ok"
endif
endif
end function
#test
open denmark.gdt -q
matrix m1 = {LRM}
matrix m2 = {IBO}
list ls = LRM IBO
matrices MS = null
MS += m1
MS += m2
print "Test with both, matrices and list"
test(MS,ls)
print "Test with neither list nor matrices"
test()
print "Test with only matrices"
test(MS)
print "Test with only list"
test(null,ls)
</hansl>
Best,
Frederik