Secure go language build target from source array slice

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

Today in the QQ group chat to go language needs to improve the place, happy to spit a groove. I'd most like to change the syntax of the array-building slice, because the popular [start:end] approach is not rigorous at the moment. Later, when I did not remember which version, I introduced the three-segment [Start:end:max] syntax to create the slice. It's safe, but it's a lot uglier.

As the following example shows, the definition of a two-segment will contaminate the source array after the Append operation:

A: = [5]int{1, 2, 3, 4, 5} S1: = A[1:3:3] S2: = A[1:3] _ = Append (S1, 6) fmt. Println (a)//out:[1 2 3 4 5] _ = Append (s2, 7) fmt. Println (a)//out:[1 2 3 7 5]


On the improvement of the new function, Chai sent me to the Mail group, thanking Chai big.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.