[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: N_ELEMENTS and WHERE: Scalar or Array ?
Craig Markwardt <craigmnet@astrog.physics.wisc.edu> wrote:
>wmc@bas.ac.uk writes:
>> ...
>> But since this has come up, & its one of my pet peeves: why cannot where
>> return a null array to indicate no-elements-match. And then array[null] would
>> match to nothing. This would allow one to say
>>
>> array[where(wurble)]='stoat'
>Amen brother! It is sadly unfortunate that where(0) returns a number
>at all. A null array -- if IDL had them! -- would be the best.
>Of course, there is the trade-off between power user and newbie user.
>Consider the following:
>wh_one = where(x GT 1)
>x[wh_ine] = 0 ; NOTE the type
>Because of the typo, the second statement would have the mysterious
>side effect of having no effect at all! (including no error message) I
>would still love to have it, but newbies might go crazy.
No, we're not going completely perl here: there is a distinction between an
undeclared variable (which would still cause an error in your example above)
and a variable initialised with a null value (which is what I would like
"where" to return). So your newbie would be safe.
In fact, would there be a problem with a "null" type, which would perhaps be
variable type #11? Then you don't have to worry about the actual value it
contains.
-W.
--
William M Connolley | wmc@bas.ac.uk | http://www.nbs.ac.uk/public/icd/wmc/
Climate Modeller, British Antarctic Survey | Disclaimer: I speak for myself