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
|
|
|