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

Re: Would you consider this a bug?

Kevin Ivory <Kevin.Ivory@linmpi.mpg.de> writes:

> David Kastrup wrote:
> > a=[3,4,5]
> > a[[2,1,0]] = a
> > 
> > a will be set to [3,4,3]
> > 
> > Would you think this a bug?
> I think this is extremely dangerous programming: you might get
> undefined or unpredictable results with almost any programming language
> in this type of case.

Disagree.  IDL is WRT to assignment a value oriented language, so one
might expect first the right side to be evaluated and then the left
side to be assigned (unless IDL can do this more efficiently without
affecting the result).

If I really wanted a to be destroyed during the operation, I could
have written
a[[2,1,0]] = temporary(a)

> The clean way of doing what you want is to
> index the right side of the expression:
> a = a[[2,1,0]]

Unfortunately, translating something like

a[[5,2,3,0,4,1]] = a
into the equivalent
a = a[[3,5,1,2,4,0]]
is not easy to do in the general case.  In my particular case, I had
some data that needed to be processed in sorted order, the results
needed to be rearranged in original order.

Something like
s = sort(a)
a = a[s]
a[s] = a

David Kastrup                                     Phone: +49-234-700-5570
Email: dak@neuroinformatik.ruhr-uni-bochum.de       Fax: +49-234-709-4209
Institut für Neuroinformatik, Universitätsstr. 150, 44780 Bochum, Germany