Thanks!

On Tuesday, 8 March 2016 02:49:52 UTC+1, Erik Schnetter wrote:
>
> Daniel 
>
> Instead of using the slicing operator `[...]`, you want to use the 
> `sub` function to create a subarray. Those retain the relation to 
> their parents. 
>
> `sub(vals, 2:length(vals))` 
>
> -erik 
>
>
> On Mon, Mar 7, 2016 at 8:21 PM, Daniel Carrera <[email protected] 
> <javascript:>> wrote: 
> > Hello, 
> > 
> > Some Julia functions act on their inputs. For example: 
> > 
> > julia> vals = [6,5,4,3] 
> > 4-element Array{Int64,1}: 
> >  6 
> >  5 
> >  4 
> >  3 
> > 
> > julia> sort!(vals); 
> > 
> > julia> vals 
> > 4-element Array{Int64,1}: 
> >  3 
> >  4 
> >  5 
> >  6 
> > 
> > 
> > However, it looks like these functions do not modify array slices: 
> > 
> > julia> vals = [6,5,4,3] 
> > 4-element Array{Int64,1}: 
> >  6 
> >  5 
> >  4 
> >  3 
> > 
> > julia> sort!(vals[2:end]) 
> > 3-element Array{Int64,1}: 
> >  3 
> >  4 
> >  5 
> > 
> > julia> vals 
> > 4-element Array{Int64,1}: 
> >  6 
> >  5 
> >  4 
> >  3 
> > 
> > 
> > Can anyone explain to me why this happens? Is this a language feature? 
> Is it 
> > at all possible to make a destructive function that acts on slices? 
> > 
> > Cheers, 
> > Daniel. 
> > 
>
>
>
> -- 
> Erik Schnetter <[email protected] <javascript:>> 
> http://www.perimeterinstitute.ca/personal/eschnetter/ 
>

Reply via email to