I would argue that the python behavior of evaluating x[1:10] twice,
both before and after the first assignment operation, is very
non-sensible and non-intuitive. Every `=` in julia evaluates its
right-hand side once, and ultimately returns that value. That way when
you chain assignments you know the exact same value gets assigned
everywhere. I don't see how you can argue that this is not sensible.

On Fri, May 9, 2014 at 3:07 AM, Keno Fischer
<[email protected]> wrote:
> The python example doesn't show anything different. The matlab example does
> in that it returns x (though not the slice assigned to). The real difference
> to python is this:
>
>>>> x = numpy.arange(1,11)
>>>> y = x[0:9] = x[1:10]
>>>> y
> array([ 3,  4,  5,  6,  7,  8,  9, 10, 10])
>
> so in python that means
> x[0:9] = x[1:10]
> y = x[1:10]
>
> whereas in Julia it means
>
> temp = x[1:10]
> x = temp
> y = temp
>
>
>
>
> On Fri, May 9, 2014 at 2:59 AM, Dominique Orban <[email protected]>
> wrote:
>>
>> Is that really the intended effect??? Python and Matlab seem much more
>> intuitive and return something sensible:
>>
>> >> x = [1:10];
>> >> x(1:9) = x(2:10)
>>
>> x =
>>      2     3     4     5     6     7     8     9    10    10
>>
>>
>> >>> import numpy
>> >>> x = numpy.arange(1,11)
>> >>> x[0:9] = x[1:10]
>> >>> x
>> array([ 2,  3,  4,  5,  6,  7,  8,  9, 10, 10])
>>
>>
>> On Thursday, May 8, 2014 8:59:58 PM UTC-7, Jeff Bezanson wrote:
>>>
>>> Yes, it is well-defined. The right-hand side is returned, which might
>>> cause some confusion here.
>>>
>>> On Thu, May 8, 2014 at 10:10 AM, Neal Becker <[email protected]> wrote:
>>> > Is the following well-defined in julia?
>>> >
>>> > julia> x = [1:10]
>>> > 10-element Array{Int64,1}:
>>> >   1
>>> >   2
>>> >   3
>>> >   4
>>> >   5
>>> >   6
>>> >   7
>>> >   8
>>> >   9
>>> >  10
>>> >
>>> > julia> x[1:9] = x[2:10]
>>> > 9-element Array{Int64,1}:
>>> >   2
>>> >   3
>>> >   4
>>> >   5
>>> >   6
>>> >   7
>>> >   8
>>> >   9
>>> >  10
>>> >
>>> > In general, are all such aliased assignments well-defined (all, as in
>>> > for
>>> > arbitrary ranges)?
>>> >
>
>

Reply via email to