← Fundamentals
Fundamentals

Assignment and reassignment

Keep the position the cursor just left.

Track the old and new values through each update of existing state.

Outcome

Predict what each assignment stores and when, including write order, simultaneous assignment and new bindings, and repair the state updates in a timeline log.

Terminology (4)Terms used in this lesson

Term on the front, definition on the back. Paste with tabs between fields and a new line between cards, or import the download in Anki as Basic.

Assignment
Stores the value computed by the right side into the selected existing target. For the scalar variables here, that replaces their current value.
Reassignment
A later assignment to an initialized variable. Results computed earlier from that variable keep their saved values.
Simultaneous assignment
An assignment to several targets using right-hand values obtained before those targets change. A reference tuple is not necessarily such a value snapshot.
Assignment expression
An assignment that also produces a result usable by another expression. The result is not the target’s old value.

Updating an existing binding

Initialization gives a binding its first value. Assignment writes a value to an existing destination; reassignment replaces a value already held there. Evaluating the right side and writing the destination are parts of an operation, and later statements see the state left by earlier ones.

When several state values depend on each other, identify which reads need the old values and which need the updated values. An exchange, for example, must retain both original values until they have reached their destinations. Compact assignment forms have native rules of their own, so inspect what they hold before relying on their appearance.

01The saved summary

Does a new extreme update the saved span?

An editor comparing two cuts wants Recall to toggle between the last two frame positions. A small navigation-log replayer reproduces those requests without opening the video. Its summary reports the visited span and total seek travel, but its state updates can lose the position needed by the next request.

Before repairing Recall, check whether the capture summary follows incoming seek events. The log has visited offsets from -3 through 8, including the start at 0. It saves that span; another event then extends the highest offset to 14. Predict the two numbers in its summary.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let lowest = -3;
let highest = 8;

const span = highest - lowest;

highest = 14;

console.log(span, highest);
A new seek extends highest to 14 after span was computed. What does this summary print?
TypeScript · terminal.sh
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
npx tsc --noEmit --strict main.ts && node main.ts

Use the selected language’s setup from the first reading and replace the file for each complete experiment. The expected results here are source-derived; the rewritten excerpts have no new native execution capture. C++ uses the track’s C++26 mode. The examples use small in-range integers.

02A recall loses its return

What survives the first recall write?

Now inspect the comparison control. The cursor is at 14 and last left -3. Recall should move to -3 and retain 14, so a second Recall can return there. The proposed two-line update writes both variables. Follow the values each line reads.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let current = 14;
let previous = -3;

current = previous;
previous = current;

console.log(current, previous);
The proposed recall should exchange current 14 and previous -3. What pair is actually printed?

03Preserve both positions

Does the compact recall save the old values?

The next candidate expresses the exchange in one statement. It starts from the same two cursor positions. Review what the selected native form puts on its right side before trusting it to retain the return position.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let current = 14;
let previous = -3;

[current, previous] = [previous, current];

console.log(current, previous);
Will this compact recall preserve both positions? Which pair is printed?

04Handle a new seek

Which cursor does the position-request branch update?

Recall also depends on regular seek events updating the saved state. Start with the cursor at 14. A request for 27 must leave the old 14 available for Recall and make 27 the cursor used after the branch. Review the native candidate rather than inferring success from a nearby print.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let previous = -3;
let current = 14;

previous = current = 27;

console.log(previous, current);
The normal seek should retain 14 as previous and move current to 27. What does this candidate print as previous/current?

05Repair the capture replay

Review the whole event sequence

Complete the replayer used to inspect navigation captures. First summarize the full visited span, then accumulate travel over each move, then repair the normal-seek and Recall paths together. The reader, request type and summary formatting are supplied; each task retains the working helpers it needs.

Frame offsets can be negative relative to sync marker 0. Recall exchanges the current and last cursor positions, so repeated Recall toggles between two locations. It does not traverse a general undo history. Repeated positions and Recall before any seek must also keep the summary accurate.

Repair the navigation capture

One stored span, an ordered travel total, then two state updates sharing the saved cursor.

  1. easy · F-ASSIGNMENT-V4-1 Report the span
  2. medium · F-ASSIGNMENT-V4-2 Add up the distance
  3. hard · F-ASSIGNMENT-V4-3 Recall the last cursor position
Sources

Report a problem in this lesson

For typos, mistakes and things that don’t work. We read every report and fix what’s wrong, but we don’t reply here, so a question won’t get an answer.