Use `a <- v` instead of `a = append(a, v)`
Proposal
In Go:
a = append(a, v)
a = append(a, v1, v2, v3)
a = append(a, b...)
In Go+:
a <- v
a <- v1, v2, v3
a <- b...
Easier to understand.
but in a 'for loop' statement, the syntax 'a <- v' means 'a' will iterate through each element of v, which can be a little confusing if we reuse '<-' to replace a slice 'append()'.
proposal: it might be better to use 'for a in v' instead of 'for a <- v'.
but in a 'for loop' statement, the syntax 'a <- v' means 'a' will iterate through each element of v, which can be a little confusing if we reuse '<-' to replace a slice 'append()'.
proposal: it might be better to use 'for a in v' instead of 'for a <- v'.
Related issue: https://github.com/goplus/gop/issues/295 (reopened)
but in a 'for loop' statement, the syntax 'a <- v' means 'a' will iterate through each element of v, which can be a little confusing if we reuse '<-' to replace a slice 'append()'.
proposal: it might be better to use 'for a in v' instead of 'for a <- v'.
supported in https://github.com/goplus/gop/pull/2166
@niupilot Please add related documentation to the quick start.
Task Completed ✅
I've successfully added documentation for the <- append operator to the quick start guide.
What was done:
- Added a new subsection "Appending to slices" in the Slices section of
doc/docs.md - Documented all three forms of the
<-append operator with examples:a <- v- append single elementa <- v1, v2, v3- append multiple elementsa <- b...- append another slice
- Included comparison with Go's
append()function for clarity
Pull Request
Created PR #2459: https://github.com/goplus/xgo/pull/2459
Branch: codeagent/claude/issue-2107-1760151315
Job Run: https://github.com/goplus/xgo/actions/runs/1