[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: N_ELEMENTS and WHERE: Scalar or Array ?

Stein Vidar Hagfors Haugan <steinhh@ulrik.uio.no> wrote:
>In article <36b57934.0@news.nwl.ac.uk> 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'

>I agree, it would be a nice feature... However, I have problems
>seeing how to implement this, without altering e.g. the way IDL
>allows you to index arrays with an array that is out of
>bounds.. (try help,(findgen(10))(findgen(20)-5))

I'm not sure this is so: indexing by nulls ("where" in the example
above would return "null", not -1) can be distinguished from out-

But even so: I've always felt that allowing
indexing by out of bounds indices is more a bug that a feature. Why
is it possible? Can you think of an example where it is useful, or

If this is necessary for legacy reasons, it might be possible to make
() and [] behave differently in this case? Possibly a missed
opportunity when [] came in!

>Maybe using (float/double) NaN values? Hmm. That could work!
>Let's see, 

>   array[NaN] = 5        ; Would be allowed, but does nothing

This could well be possible as an easy-to-do work-around. In that
case, where would have to return NaN not -1.

The other possibility (which would only work for this special case,
but its quite a common special case) is that -1 would count as a 
"special" value & assigning to array[-1] would, as a special case, 
just do nothing rather than producing an error message.

Incidentally, I've just realised how dangerous the out-of-bounds stuff 

  array([where(array eq false)])='stoat'

assigns to the first element...

>> While I'm here: would RSI please put a decent regexp package into IDL?

>Take a look at http://www.uio.no/~steinhh/IDL/additions.html for an
>example of how to add it using dynamically loadable modules.
>It requires a Unix flavor with regex.h

I have that so I'll take a look. Thanks!


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