Re: LIST "bug": .Remove on an empty list [message #74016 is a reply to message #73994] |
Fri, 17 December 2010 09:35  |
penteado
Messages: 866 Registered: February 2018
|
Senior Member Administrator |
|
|
On Dec 14, 1:35 pm, Paul van Delst <paul.vande...@noaa.gov> wrote:
> Thinking about it a little more, I think I'm biased against IDL and thus making bad design decisions (sorry!). If there
> was a list "Empty" or "IsEmpty" method (like ruby's "empty?" method...for both arrays/lists and hashes), I would be more
> tempted to use it,
>
> if ( l.isempty() ) then ...return, handle error, whatever...
>
> as opposed to the current IDL idiom,
>
> if ( n_elements(l) eq 0 ) then ...return, handle error, whatever...
I just remembered that there is not much need for IsEmpty, as the
lists currently already overload their truth value (to the opposite;
an empty list evaluates to false):
IDL> l=list()
IDL> if (~l) then print,'empty list' else print,'list has
',n_elements(l),' elements'
empty list
IDL> l.add,9
IDL> if (~l) then print,'empty list' else print,'list has
',n_elements(l),' elements'
list has 1 elements
And I find "if (~l) then ..." much more convenient than "if
(l.isempty()) then ...".
|
|
|