Re: IDL 8.0 compile_opt changes [message #69462 is a reply to message #69187] |
Thu, 07 January 2010 07:27   |
Maarten[1]
Messages: 176 Registered: November 2005
|
Senior Member |
|
|
On Jan 6, 10:25 pm, mgalloy <mgal...@gmail.com> wrote:
> On 1/6/10 7:01 AM, Maarten wrote:
>
>> I do love the idea of negative indices, although I'd like them to mean
>> the same as in Python. The samples Ive seen so far are off by one.
>
> My understanding of the negative indices proposal in IDL was that they
> would be the same as in Python:
>
>>>> a = [1, 2, 3, 4]
>>>> a[-1]
> 4
>>>> a[-2]
> 3
Yes, in this case it is the same. The (subtle) difference comes in for
ranges.
Python:
>>> a = [1,2,3,4]
>>> a[-1]
4
>>> a[-2]
3
>>> a[1:-1]
[2, 3]
The last one is the one I'm concerned about, as python does not
include the last index in the range.
IDL> a = [1,2,3,4]
IDL> print, a[3]
4
IDL> print, a[1:3]
2 3 4
(index 3 is equivalent to index -1).
Now you could say that Python and IDL already disagree here, but the
off-by-one is worth mentioning anyway.
> By the way, this could break old code as well. It also seems like a
> better reason for breaking backward compatibility than the "." as a
> method invocation.
Agreed.
> And once backwards compatibility is broken, then we
> might as well make all the changes we need at once (as long as we have a
> good conversion tool that makes most of the changes automatically).
A conversion tool may not have to go forward. It may be easier to go
backward with a tool. Especially since this allows for cleaning up the
syntax. It will also prompt users to write code for the newer system,
and let a tool worry about backward compatibility (compare to Python
3).
Maarten
|
|
|