Clarify slices vs. arrays a bit

Highlight slices in the opening description of the arrays example, to
grab attention of new users
This commit is contained in:
Eli Bendersky 2022-09-08 05:37:20 -07:00
parent 1b4dac72d3
commit 742fab3f1c
7 changed files with 18 additions and 29 deletions

View File

@ -1,5 +1,7 @@
// In Go, an _array_ is a numbered sequence of elements of a
// specific length.
// specific length. In typical Go code, [slices](slices) are
// much more common; arrays are useful in some special
// scenarios.
package main

View File

@ -1,2 +1,2 @@
e71f2d3763eb2950727faa39b90cf1bc037d85fa
TaahifSGSwU
e2bdc11af83f9c6964cfa0e06e4642943b3055ae
bBVikSoZ1Z7

View File

@ -7,6 +7,3 @@ get: 100
len: 5
dcl: [1 2 3 4 5]
2d: [[0 1 2] [1 2 3]]
# You'll see _slices_ much more often than arrays in
# typical Go. We'll look at slices next.

View File

@ -1,5 +1,5 @@
// _Slices_ are a key data type in Go, giving a more
// powerful interface to sequences than arrays.
// _Slices_ are an important data type in Go, giving
// a more powerful interface to sequences than arrays.
package main

View File

@ -1,2 +1,2 @@
02c5330eb3ef32a88ca22a5adbded9bd356f89f3
iLnoIEIxeQ1
13835b88336e031808f2f3887cd43d0b9d85cad0
76f4Jif5Z8o

22
public/arrays generated
View File

@ -28,7 +28,9 @@
<tr>
<td class="docs">
<p>In Go, an <em>array</em> is a numbered sequence of elements of a
specific length.</p>
specific length. In typical Go code, <a href="slices">slices</a> are
much more common; arrays are useful in some special
scenarios.</p>
</td>
<td class="code empty leading">
@ -42,7 +44,7 @@ specific length.</p>
</td>
<td class="code leading">
<a href="https://go.dev/play/p/TaahifSGSwU"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<a href="https://go.dev/play/p/bBVikSoZ1Z7"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<pre class="chroma"><span class="kn">package</span> <span class="nx">main</span>
</pre>
</td>
@ -164,7 +166,7 @@ structures.</p>
when printed with <code>fmt.Println</code>.</p>
</td>
<td class="code leading">
<td class="code">
<pre class="chroma">
<span class="gp">$</span> go run arrays.go
@ -177,18 +179,6 @@ when printed with <code>fmt.Println</code>.</p>
</td>
</tr>
<tr>
<td class="docs">
<p>You&rsquo;ll see <em>slices</em> much more often than arrays in
typical Go. We&rsquo;ll look at slices next.</p>
</td>
<td class="code empty">
</td>
</tr>
</table>
@ -204,7 +194,7 @@ typical Go. We&rsquo;ll look at slices next.</p>
</div>
<script>
var codeLines = [];
codeLines.push('');codeLines.push('package main\u000A');codeLines.push('import \"fmt\"\u000A');codeLines.push('func main() {\u000A');codeLines.push(' var a [5]int\u000A fmt.Println(\"emp:\", a)\u000A');codeLines.push(' a[4] \u003D 100\u000A fmt.Println(\"set:\", a)\u000A fmt.Println(\"get:\", a[4])\u000A');codeLines.push(' fmt.Println(\"len:\", len(a))\u000A');codeLines.push(' b :\u003D [5]int{1, 2, 3, 4, 5}\u000A fmt.Println(\"dcl:\", b)\u000A');codeLines.push(' var twoD [2][3]int\u000A for i :\u003D 0; i \u003C 2; i++ {\u000A for j :\u003D 0; j \u003C 3; j++ {\u000A twoD[i][j] \u003D i + j\u000A }\u000A }\u000A fmt.Println(\"2d: \", twoD)\u000A}\u000A');codeLines.push('');codeLines.push('');
codeLines.push('');codeLines.push('package main\u000A');codeLines.push('import \"fmt\"\u000A');codeLines.push('func main() {\u000A');codeLines.push(' var a [5]int\u000A fmt.Println(\"emp:\", a)\u000A');codeLines.push(' a[4] \u003D 100\u000A fmt.Println(\"set:\", a)\u000A fmt.Println(\"get:\", a[4])\u000A');codeLines.push(' fmt.Println(\"len:\", len(a))\u000A');codeLines.push(' b :\u003D [5]int{1, 2, 3, 4, 5}\u000A fmt.Println(\"dcl:\", b)\u000A');codeLines.push(' var twoD [2][3]int\u000A for i :\u003D 0; i \u003C 2; i++ {\u000A for j :\u003D 0; j \u003C 3; j++ {\u000A twoD[i][j] \u003D i + j\u000A }\u000A }\u000A fmt.Println(\"2d: \", twoD)\u000A}\u000A');codeLines.push('');
</script>
<script src="site.js" async></script>
</body>

6
public/slices generated
View File

@ -27,8 +27,8 @@
<tr>
<td class="docs">
<p><em>Slices</em> are a key data type in Go, giving a more
powerful interface to sequences than arrays.</p>
<p><em>Slices</em> are an important data type in Go, giving
a more powerful interface to sequences than arrays.</p>
</td>
<td class="code empty leading">
@ -42,7 +42,7 @@ powerful interface to sequences than arrays.</p>
</td>
<td class="code leading">
<a href="https://go.dev/play/p/iLnoIEIxeQ1"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<a href="https://go.dev/play/p/76f4Jif5Z8o"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<pre class="chroma"><span class="kn">package</span> <span class="nx">main</span>
</pre>
</td>