Yes.
If you manipulate the meaning of the index (i) or the length of the slice,
then do it explicitly:
for i := 0; i < len(a); i++ {
if a[i] == 0 { //delete
a[i]=a[0]
a = a[1:]
i--
}
}
For other methods, see
https://go.dev/wiki/SliceTricks#filtering-without-allocating
Shivansh
Hi Guys, I had a question regarding:
> On the other hand, if you have `for i, v := range a {` then the
> expression *is* evaluated before the start of the loop.
I have a code (https://goplay.tools/snippet/dMwD0_rEhkB) where I am ranging
over a slice, and updating (removing the zeroth element for
[Sorry, I accidentally set the Reply-To incorrectly in my previous msg;
corrected here. I don't need a CC in responses.]
* Jan Mercl <0xj...@gmail.com> [220318 12:04]:
> On Fri, Mar 18, 2022 at 4:53 PM 'Axel Wagner' via golang-nuts
> wrote:
> > I don't really know the answer to your question. I
On Fri, Mar 18, 2022 at 4:53 PM 'Axel Wagner' via golang-nuts
wrote:
>
> One thing to keep in mind is that Go development was incremental and was
> done, from early on, by having multiple implementations. Incremental
> processes often lead to different results than designing a language from a
>
One thing to keep in mind is that Go development was incremental and was
done, from early on, by having multiple implementations. Incremental
processes often lead to different results than designing a language from a
blank slate. Ambiguities in the spec are often discovered only when someone
notice
* 'Axel Wagner' via golang-nuts [220318 08:04]:
> https://go.dev/ref/spec#Length_and_capacity says:
>
> > The expression len(s) is constant if s is a string constant. The
> > expressions len(s) and cap(s) are constants if the type of s is an array or
> > pointer to an array and the expression s d
Thanks Axel,
Now this makes sense to me.
All the best,
Jochen
On Friday, 18 March 2022 at 12:04:04 UTC axel.wa...@googlemail.com wrote:
> https://go.dev/ref/spec#Length_and_capacity says:
>
>> The expression len(s) is constant if s is a string constant. The
>> expressions len(s) and cap(s) are
https://go.dev/ref/spec#Length_and_capacity says:
> The expression len(s) is constant if s is a string constant. The
> expressions len(s) and cap(s) are constants if the type of s is an array or
> pointer to an array and the expression s does not contain channel receives
> or (non-constant) functi
On Fri, 2022-03-18 at 04:43 -0700, Jochen Voss wrote:
> Dear all,
>
> The spec at https://go.dev/ref/spec#For_range says
>
> "The range expression x is evaluated once before beginning the loop,
> with one exception: if at most one iteration variable is present
> and len(x) is constant, the range ex
On Fri, Mar 18, 2022 at 12:43 PM Jochen Voss wrote:
> The spec at https://go.dev/ref/spec#For_range says
>
> "The range expression x is evaluated once before beginning the loop, with one
> exception: if at most one iteration variable is present and len(x) is
> constant, the range expression is n
Dear all,
The spec at https://go.dev/ref/spec#For_range says
"The range expression x is evaluated once before beginning the loop, with
one exception: if at most one iteration variable is present and len(x) is
constant, the range expression is not evaluated."
What does the second half of this
11 matches
Mail list logo