Yep, Python documentation is quite good, and Julia's has a little ways to go. (Did you see Python's documentation 10 years ago, though? ;-)
There wasn't much, if any, documentation about n:n-1 empty ranges or splicing without removal, so I just added some ( https://github.com/JuliaLang/julia/pull/7631). These will appear online as soon as someone regenerates the documentation (it might take a few days). The main sections I updated are http://docs.julialang.org/en/latest/manual/arrays/#indexing and http://docs.julialang.org/en/latest/stdlib/base/#Base.splice!. The updates are minimal, though, and so it's still possible to overlook. I was thinking that your first question/point actually makes some sense. push! allows adding multiple items at the end of a list via push!(list, 1,2,3) so it would make sense that you could also do insert!(list, 4, 'a', 'b', 'c') It also might make sense to have a `splicein!` or `insertat!` function, which just inserts values into a collection and returns the full collection. (Issue discussing this is here: https://github.com/JuliaLang/julia/issues/7632 Cheers! Kevin On Wed, Jul 16, 2014 at 5:41 PM, Michael Louwrens < [email protected]> wrote: > Thanks! > > Could you perhaps point me to a place where these sort of things may be > documented? > Trying to adopt the language has been less painful than Python was. Python > however, has better documentation currently for these kind of small things. > Python is also far more mature so go_figure! (go_figure! alters its > contents :D) > It may just be me however missing an obvious result in Google. > > > On Wednesday, 16 July 2014 03:11:30 UTC+2, Kevin Squire wrote: > >> Hi Michael, >> >> You can actually use splice!: >> >> julia> splice!(x, 3:2, y) >> 0-element Array{Int64,1} >> >> julia> x >> 8-element Array{Int64,1}: >> 1 >> 2 >> 3 >> 4 >> 5 >> 6 >> 7 >> 8 >> >> 3:2 is a convention in julia that indicates the (empty) location in the >> array between index 2 and index 3 (e.g., searchsorted(x,3) for your >> original x will return 3:2 as the insertion point). >> >> Note that splice returns any removed ("spliced out") elements, which is >> why the return value of the first command above is empty >> >> Hope this helps! >> >> Cheers, >> Kevin >> >> >> On Tue, Jul 15, 2014 at 5:23 PM, Michael Louwrens <michael.w...@outlook. >> com> wrote: >> >>> Should insert! not be able to insert a collection? >>> >>> x = [1,2,7,8] >>> y = [3,4,5,6] >>> insert!(x,2+1,y) >>> >>> Is then unable to complete the insertion and create [1,2,3,4,5,6,7,8]. >>> There is a costlier way to do this at the moment however. >>> >>> splice! almost replicates the required functionality but it replaces the >>> item at 2 instead of inserting items after position2. >>> >>> x = [1,2,7,8] >>> y = [3,4,5,6] >>> splice!(x,2,unshift!(y,x[2])) >>> >>> This is about 20% slower but does work. >>> >>> I was surprised that insert! inserts the item before the item at that >>> index instead of after. Could this perhaps be mentioned in the doc for >>> insert!? >>> Perhaps my Google-Fu is weak, but I could not find any reference to say >>> which behaviour it should have. >>> >>> Just wanted to point out that currently insert! only works for a single >>> item instead of a single item and collections and to inquire if there is >>> not perhaps a better workaround than the above. >>> >>> Thanks! >>> >> >>
