Page 1 of 1

Detecting Empty Lists

Posted: 26 Feb 2014 23:20
by 98b427af
The isEmpty() function does not distinguish between a list with zero elements and a null variable. What's the best way to tell them apart?

Re: Detecting Empty Lists

Posted: 27 Feb 2014 16:26
by Martin
You can check for null:
list == null
or check if list is not null:
list != null

Re: Detecting Empty Lists

Posted: 27 Feb 2014 16:55
by 98b427af
Thanks!

Re: Detecting Empty Lists

Posted: 28 Feb 2014 22:05
by 98b427af
A further note on this: isEmpty() returns true for null (undefined) variables, empty strings ("") and empty lists ([]), but *not* for empty maps ({}).

The isEmpty() behavior is thus inconsistent, and there is no way to determine if a map is defined but empty.

Re: Detecting Empty Lists

Posted: 28 Feb 2014 22:15
by 98b427af
Also, even though you can treat a map as a string in many functions (substring, for example), the test

aMap == "{}"

returns false.

Re: Detecting Empty Lists

Posted: 28 Feb 2014 22:19
by 98b427af
One more thing:

x = newMap();
matches(x, '\\{\\}')

returns true.

Re: Detecting Empty Lists

Posted: 01 Mar 2014 12:44
by Martin
isEmpty does not exist for maps yet so map is converted to a string when the function is called. This is also the case for other method calls. I will add a new isEmpty function specifically for maps.

"{}" is not valid since it will try to evaluate the expression inside the braces and fails. A comparison newMap()=='{}' should work since the curly braces are not interpreted within single quotes.