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:
parent
1b4dac72d3
commit
742fab3f1c
@ -1,5 +1,7 @@
|
|||||||
// In Go, an _array_ is a numbered sequence of elements of a
|
// 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
|
package main
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
e71f2d3763eb2950727faa39b90cf1bc037d85fa
|
e2bdc11af83f9c6964cfa0e06e4642943b3055ae
|
||||||
TaahifSGSwU
|
bBVikSoZ1Z7
|
||||||
|
@ -7,6 +7,3 @@ get: 100
|
|||||||
len: 5
|
len: 5
|
||||||
dcl: [1 2 3 4 5]
|
dcl: [1 2 3 4 5]
|
||||||
2d: [[0 1 2] [1 2 3]]
|
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.
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// _Slices_ are a key data type in Go, giving a more
|
// _Slices_ are an important data type in Go, giving
|
||||||
// powerful interface to sequences than arrays.
|
// a more powerful interface to sequences than arrays.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
02c5330eb3ef32a88ca22a5adbded9bd356f89f3
|
13835b88336e031808f2f3887cd43d0b9d85cad0
|
||||||
iLnoIEIxeQ1
|
76f4Jif5Z8o
|
||||||
|
22
public/arrays
generated
22
public/arrays
generated
@ -28,7 +28,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="docs">
|
<td class="docs">
|
||||||
<p>In Go, an <em>array</em> is a numbered sequence of elements of a
|
<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>
|
||||||
<td class="code empty leading">
|
<td class="code empty leading">
|
||||||
@ -42,7 +44,7 @@ specific length.</p>
|
|||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code leading">
|
<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 class="chroma"><span class="kn">package</span> <span class="nx">main</span>
|
||||||
</pre>
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
@ -164,7 +166,7 @@ structures.</p>
|
|||||||
when printed with <code>fmt.Println</code>.</p>
|
when printed with <code>fmt.Println</code>.</p>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code leading">
|
<td class="code">
|
||||||
|
|
||||||
<pre class="chroma">
|
<pre class="chroma">
|
||||||
<span class="gp">$</span> go run arrays.go
|
<span class="gp">$</span> go run arrays.go
|
||||||
@ -177,18 +179,6 @@ when printed with <code>fmt.Println</code>.</p>
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="docs">
|
|
||||||
<p>You’ll see <em>slices</em> much more often than arrays in
|
|
||||||
typical Go. We’ll look at slices next.</p>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
<td class="code empty">
|
|
||||||
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
@ -204,7 +194,7 @@ typical Go. We’ll look at slices next.</p>
|
|||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
var codeLines = [];
|
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>
|
||||||
<script src="site.js" async></script>
|
<script src="site.js" async></script>
|
||||||
</body>
|
</body>
|
||||||
|
6
public/slices
generated
6
public/slices
generated
@ -27,8 +27,8 @@
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="docs">
|
<td class="docs">
|
||||||
<p><em>Slices</em> are a key data type in Go, giving a more
|
<p><em>Slices</em> are an important data type in Go, giving
|
||||||
powerful interface to sequences than arrays.</p>
|
a more powerful interface to sequences than arrays.</p>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code empty leading">
|
<td class="code empty leading">
|
||||||
@ -42,7 +42,7 @@ powerful interface to sequences than arrays.</p>
|
|||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td class="code leading">
|
<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 class="chroma"><span class="kn">package</span> <span class="nx">main</span>
|
||||||
</pre>
|
</pre>
|
||||||
</td>
|
</td>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user