I just used the following bit of code in an Advent of Code puzzle, to sequentially alter a vector by removing one of its elements in turn:
deleteat!(copy(r), i) for i in 1:length(r)
I believe I had to use copy()
here, because the only available version of deleteat()
is the modifying version with !
.
I get that there are various workarounds to this, but my n00b question is just simply: why would there be only a modifying function in base Julia, and no ‘standard’ version of the function available? (I think there are lots of other functions that seem to only have !
versions, too).
Why doesn’t Julia want me to do
deleteat(r, i) for i in 1:length(r)
?
I’m used to being able to do this in R with [
and a negative index, like this:
lapply(seq_along(x), \(i) x[-i])
but I don’t think Julia supports negative indices like this?
Thanks!