Skip to content

Commit 50e8944

Browse files
committed
Improve Basics: iota explanation callout and pointer memory diagram
1 parent e53472b commit 50e8944

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

basics.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,22 @@
362362

363363
.callout-icon { flex-shrink: 0; font-size: 1rem; margin-top: 1px; }
364364

365+
.diagram {
366+
background: var(--surface);
367+
border: 1px solid var(--border);
368+
border-radius: var(--radius);
369+
padding: 20px 24px;
370+
margin-bottom: 20px;
371+
overflow-x: auto;
372+
}
373+
374+
.diagram pre {
375+
font-family: var(--font-mono);
376+
font-size: .8rem;
377+
line-height: 1.8;
378+
color: var(--text);
379+
}
380+
365381
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
366382

367383
.ref-table {
@@ -588,6 +604,11 @@ <h2>Constants &amp; iota</h2>
588604
</div>
589605
</div>
590606

607+
<div class="callout tip">
608+
<span class="callout-icon">💡</span>
609+
<div>Use <code>iota</code> when you need a set of related constants that don't have meaningful numeric values themselves — like states, directions, or flags. It removes hardcoded numbers, so inserting or reordering values never causes silent bugs from miscounted integers.</div>
610+
</div>
611+
591612
<div class="card">
592613
<div class="card-header">
593614
<span class="card-title">iota patterns — bitmasks &amp; expressions</span>
@@ -629,6 +650,21 @@ <h2>Pointers</h2>
629650
<span class="section-tag">&amp; · * · nil</span>
630651
</div>
631652

653+
<div class="diagram">
654+
<pre> Regular variable Pointer variable
655+
656+
x := 42 p := &amp;x
657+
658+
┌───────────┐ ┌───────────┐ ┌───────────┐
659+
│ 42 │ │ 0xc000 │────────▶│ 42 │
660+
└───────────┘ └───────────┘ └───────────┘
661+
addr: 0xc000 addr: 0xc008 addr: 0xc000
662+
x p *p
663+
664+
x holds the value directly. p holds the address of x.
665+
Changing x affects only x. *p reads or writes x through the address.</pre>
666+
</div>
667+
632668
<div class="card">
633669
<div class="card-header">
634670
<span class="card-title">Address &amp; dereference</span>

0 commit comments

Comments
 (0)