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

*Subject*: Re: Array subscript question*From*: Steve Hartmann <slh(at)vuse.vanderbilt.edu>*Date*: Thu, 02 Mar 2000 18:16:48 -0600*Newsgroups*: comp.lang.idl-pvwave*Organization*: Vanderbilt University usenet news server*References*: <bowman-0203001611240001@bowman.tamu.edu>*Xref*: news.doit.wisc.edu comp.lang.idl-pvwave:18755

"Kenneth P. Bowman" wrote: > Can someone explain this behavior to me? I can't find anything in the > documentation that states that repeated subscripts are handled > differently. > > IDL> a = FINDGEN(5) > IDL> i = [1, 2, 3] > IDL> a[i] = a[i] + 10.0 > IDL> PRINT, a > 0.00000 11.0000 12.0000 13.0000 4.00000 > > This is the behavior I expect. > > IDL> a = FINDGEN(5) > IDL> i = [2, 2, 2] > IDL> a[i] = a[i] + 10.0 > IDL> PRINT, a > 0.00000 1.00000 12.0000 3.00000 4.00000 > > Why does it only do the operation *once* when > IDL> HELP, a[i] > <Expression> FLOAT = Array[3] > > IDL> a = FINDGEN(5) > IDL> i = [2, 2, 2] > IDL> a[i] = a[i] + [10.0, 10.0, 10.0] > IDL> PRINT, a > 0.00000 1.00000 12.0000 3.00000 4.00000 > > Even this doesn't help. > > Ken > > The expression on the right is evaluated first. So your last example, a[i] = a[i] + [10.0, 10.0, 10.0] could be written as, [ a[2], a[2], a[2] ] = [ a[2], a[2], a[2] ] + [10.0, 10.0, 10.0] or, [ a[2], a[2], a[2] ] = [ 12.0, 12.0, 12.0 ] which is the same as, a[2] = 12.0 a[2] = 12.0 a[2] = 12.0 So the operation does occur more than once, but it's just the same operation. If you try a[i] = a[i] + [x, y, z], a[2] will equal 'z', since that expression was executed last. I hope this helps, Steve Hartmann

**References**:**Array subscript question***From:*Kenneth P. Bowman

- Prev by Date:
**Re: Array subscript question** - Next by Date:
**Re: Problem with ASSOC,/PACKED** - Prev by thread:
**Re: Array subscript question** - Next by thread:
**Mouse cursor position** - Index(es):