On Sunday, October 16, 2016 at 4:54:45 PM UTC, Yichao Yu wrote: > > > > On Sun, Oct 16, 2016 at 12:01 PM, Páll Haraldsson <pall.ha...@gmail.com > <javascript:>> wrote: > >> >> I was prototyping: >> >> julia> a=[1,2,3,1,2] >> >> julia> b=[a[i]<a[i+1] for i in 1:length(a)-1] >> 4-element Array{Bool,1}: >> true >> true >> false >> true >> >> >> In the beginning when trying stuff out I used: >> >> for i in a[1:end-1] >> >> or >> >> for i in a[2:end] >> >> and it got me thinking, end-1 works for any kind of array, but 1 as the >> start (or 2) is not correct in general. For e.g. general (e.g. zero-based >> arrays now allowed), what do you do? [If I need all: for i in a just works] >> >> > Not decided yet. Ref https://github.com/JuliaLang/julia/pull/15750 >
Thanks for answering. And from this I see: https://github.com/JuliaArrays/EndpointRanges.jl [I'm not clear on (proposed?) "last" vs. "end"; maybe it's just for a demo, as it would else conflict, if "first" (or "ibegin") and "last" or "iend" ends up as decided then hopefully soon as a breaking change.. This could stay in a package forever, but not good as a replacement for "1" is needed..] To get one thing clear, "end" continues to work, for the last element, but since "1" should now be "considered harmful".. "end" may not be very useful ("end:end" is still possible and "end-1:end" etc.. but not much else). I know about eachindex (or ways for whole arrays/collections), but do not need each.. What works now to get the second (or first)? Is something like view(a, 2:length(a)) # for 1D.. a workaround? > https://github.com/JuliaLang/julia/pull/15558 <https://github.com/JuliaLang/julia/pull/15558> > You can always use an assignment in a composite expression. Not sure what you mean, but may not be important as @inbounds isn't a big deal [for me] as I think I'll always need a for loop anyway (no big problem).