Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Go Arrays & Slices
Search
Nathan Youngman
May 25, 2015
Programming
0
160
Go Arrays & Slices
An overview of how slices and arrays work in Go.
Nathan Youngman
May 25, 2015
Tweet
Share
More Decks by Nathan Youngman
See All by Nathan Youngman
The Healthy Programmer
nathany
2
120
Go and Node.js: a comparison
nathany
1
240
Diet Hacks
nathany
2
390
Go 1.6 and HTTP/2
nathany
3
150
Upgrading Rails Redux
nathany
1
97
GopherCon recap
nathany
0
190
Go Functions
nathany
0
110
Go Types
nathany
2
140
Go Packages
nathany
2
560
Other Decks in Programming
See All in Programming
Claude Code の Skill で複雑な既存仕様をすっきり整理しよう
yuichirokato
1
360
Vuetify 3 → 4 何が変わった?差分と移行ポイント10分まとめ
koukimiura
0
110
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
130
ふつうの Rubyist、ちいさなデバイス、大きな一年
bash0c7
0
820
Go1.26 go fixをプロダクトに適用して困ったこと
kurakura0916
0
360
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
490
「やめとこ」がなくなった — 1月にZennを始めて22本書いた AI共創開発のリアル
atani14
0
370
AI時代のソフトウェア開発でも「人が仕様を書く」から始めよう-医療IT現場での実践とこれから
koukimiura
0
140
モジュラモノリスにおける境界をGoのinternalパッケージで守る
magavel
0
3.5k
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
130
Docコメントで始める簡単ガードレール
keisukeikeda
1
110
Claude Code Skill入門
mayahoney
0
180
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
300
Everyday Curiosity
cassininazir
0
160
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
350
The Curse of the Amulet
leimatthew05
1
9.8k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
Discover your Explorer Soul
emna__ayadi
2
1.1k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
The Language of Interfaces
destraynor
162
26k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
The Cost Of JavaScript in 2023
addyosmani
55
9.8k
Transcript
gophers := [4]string{"blue", "pink", "purple", "blue"}
Arrays are fixed-length planets := [8]string{ "Mercury", "Venus", "Earth", "Mars",
"Jupiter", "Saturn", "Uranus", "Neptune", } 0 1 2 3 4 5 6 7
Arrays are values planetBackup := planets // make way
for an interstellar bypass planets[2] = “" fmt.Println(planets) // [Mercury Venus Mars Jupiter Saturn Uranus Neptune] fmt.Println(planetBackup) // [Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune]
Slicing makes a window terrestrial := planets[0:4] gasGiants := planets[4:6]
iceGiants := planets[6:8] 0 1 2 3 4 5 6 7 terrestrial gasGiants iceGiants
Half-open range planets[2:3] // [Earth] < 3 • starts at
index 2 • excludes index 3
Defaults terrestrial := planets[:4] gasGiants := planets[4:6] iceGiants := planets[6:]
allPlanets := planets[:]
Making a slice // allPlanets := planets[:] planets := []string{
"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", }
Append to slices planets = append(planets, "Pluto") 0 1 2
3 4 5 6 7 8 9 10 11 12 13 14 15 fmt.Println(len(planets), cap(planets)) // 9 16
Append again planets = append(planets, "Eris", "Sedna") fmt.Println(len(planets), cap(planets))
// 11 16
http://blog.golang.org/go-slices-usage-and-internals https://github.com/golang/go/wiki/SliceTricks More reading