Dictionary error does not generate error [message #89537] |
Fri, 24 October 2014 04:12  |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
Hi,
the help the dictionary() function states at the end (from http://www.exelisvis.com/docs/DICTIONARY.html):
;*** Start citation ***
Difference between Dictionary and IDL Structures
Unlike IDL structures, when indexing into an array within a dictionary, you can not use the "dot" notation to retrieve the key's value and then index into the "dot" value. This is because the DICTIONARY is implemented as a "container" of data pointers instead of a structure that is laid out directly into memory. For example:
str = {data: FINDGEN(10)}
PRINT, str.data
PRINT, str.data[2:5] ; this works
dict = DICTIONARY('data', FINDGEN(10))
PRINT, dict.data ; this works
PRINT, dict.data[2:5] ; this will fail with an error
PRINT, dict['data', [2:5]] ; this works correctly
;*** end citation ***
If I insert the dictionary part in IDL 8.4, I get:
IDL> dict = DICTIONARY('data', FINDGEN(10))
IDL> PRINT, dict.data ; this works
IDL> PRINT, dict.data[2:5] ; this will fail with an error
IDL> PRINT, dict['data', [2:5]] ; this works correctly
0.000000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000
2.00000 3.00000 4.00000 5.00000
2.00000 3.00000 4.00000 5.00000
To me, that works just as the structure (correctly, should I say?).
Has this been repaired in 8.4 as compared to 8.3 or previous versions? Or are there other problems connected with indexing of dictionaries?
It's quite important I get this straight, because I'm using dictionaries quite intensively.
Thanks,
Helder
|
|
|
|
Re: Dictionary error does not generate error [message #89539 is a reply to message #89538] |
Fri, 24 October 2014 05:02  |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Friday, October 24, 2014 1:53:31 PM UTC+2, Fabien wrote:
> IDL 8.3:
>
> IDL> dict = DICTIONARY('data', FINDGEN(10))
> IDL> PRINT, dict.data[2:5]
> % Subscripts are not allowed with object properties.
> % Execution halted at: $MAIN$
> IDL> PRINT, (dict.data)[2:5]
> 2.00000 3.00000 4.00000 5.00000
>
> IF the syntax: dict.data[2:5] now works in 8.4, this would be so great!
> The use of () makes nested dictionaries really cumbersome to use
Well, it's looking good in 8.4, so as you said... one can get rid of quite some (). Good.
Cheers,
Helder
|
|
|