s LearnSqueak.com

PRACTICAL SQUEAK WORKSHOP

Build an editable expense table

Build a native grid of editable cells, validate each draft, total integer cents, sort by stable identity, and round-trip a bounded CSV format.

9 construction stagesTested source & checkpointsNative screenshots & demos
Try the finished example

Run in the SqueakJS playground

The separate playground loads the real Smalltalk image on demand. This lesson keeps its native setup instructions; browser compatibility notes appear beside each demo.

Before you start

Build a native grid of editable cells, validate each draft, total integer cents, sort by stable identity, and round-trip a bounded CSV format.

Classes and objects · Using Squeak’s tools

  • Save a copy of your Squeak image first. Each numbered .st file is a complete cumulative checkpoint that can be filed into a fresh Squeak 6.1 image.
  • Download the checkpoint beside your image. In File List, select it and choose fileIn. The method excerpt below is for the System Browser; it is already installed by the file. The separate Workspace block opens the exact demonstrated state.
  • Close the previous checkpoint window before moving to the next. The app uses a fixed-size SystemWindow; its rows and appointment lists scroll. File the final app before its test source, then use Test Runner to run LQExpenseTests.
  • All examples use fictional data and local files. Snapshot examples create UUID-named new files beside your image. Keep any snapshots you want; no example overwrites a previous snapshot.

01 · Rows are data

The book owns an ordered collection of five-element arrays: ID, date text, category, description, and integer cents. The view builds one native button for each cell, so the table has a real row and column structure. A sample population method adds three fictional purchases when the window opens. The ID is created once and stays with the record; a screen row number is only a temporary position.

Where to run this

System Browser, LQExpenseBook, instance side. Find the method beginning initialize. This excerpt is already installed by checkpoint 01; do not paste a method definition into Workspace.

Construction code · follow the run instructions above
initialize
 super initialize.
 rows := OrderedCollection new.
 nextId := 1.
 selectedId := nil.
 sortColumn := 1.
 ascending := true.
 dirty := false.
 status := 'Fictional expenses. Click a cell to edit at checkpoint 2.'.
 io := LQCalendarTableIO new

After filing in this checkpoint, evaluate the complete block in Workspace with Do it (Ctrl+D / Cmd+D). It returns the app.

Workspace · run after installing this checkpoint
LQExpenseApp open
  • nextId creates monotonically increasing row keys
  • rows deepCopy prevents callers from changing the stored arrays by accident
  • The first checkpoint can select an ID; subsequent checkpoints unlock editing and sorting

Amounts are stored as cents from the first checkpoint, even before the total is displayed. This is an expense table with dialog-based cell editing, not a spreadsheet formula engine.

Expected result

Three fictional rows appear, with ID, Date, Category, Description, and Amount columns.

Download this checkpoint source

NATIVE SQUEAK CAPTURE
Rows are data in native Squeak 6.1
Native Squeak 6.1 checkpoint 01, rendered after executing the exact Workspace block above.

02 · Edit one cell

A cell button sends its permanent ID and column number to the app. The app asks for a replacement string with the existing value prefilled. The model copies the four editable values into a draft and replaces one draft field. Only after the whole draft validates does it replace the original row. Cancelling produces nil, which is distinct from an empty string. IDs are deliberately read-only.

Where to run this

System Browser, LQExpenseBook, instance side. Find the method beginning editId:. This excerpt is already installed by checkpoint 02; do not paste a method definition into Workspace.

Construction code · follow the run instructions above
editId: id column: column text: text
 | original fields draft |
 text ifNil: [status := 'Edit cancelled. The cell is unchanged.'. ^ false].
 (column between: 2 and: 5) ifFalse: [status := 'ID is read-only.'. ^ false].
 original := self rowId: id.
 original ifNil: [status := 'Row no longer exists.'. ^ false].
 fields := {original second. original third. original fourth. self money: original fifth}.
 fields at: column - 1 put: text.
 draft := self draftDate: fields first category: fields second description: fields third amount: fields fourth.
 draft ifNil: [^ false].
 rows at: (rows indexOf: original) put: ({id}, draft).
 selectedId := id.
 dirty := true.
 status := 'Cell committed after validation. Unsaved changes.'.
 ^ true

After filing in this checkpoint, evaluate the complete block in Workspace with Do it (Ctrl+D / Cmd+D). It returns the app.

Workspace · run after installing this checkpoint
| app |
app := LQExpenseApp open.
app book editId: 2 column: 4 text: 'Graph paper'.
app refresh.
app
  • The original record is looked up by ID, not by its current sorted position
  • column - 1 maps the table column into the four-field draft
  • The single rows at:put: message is the commit point

Click any Date, Category, Description, or Amount cell to edit. Click its ID to select without opening a dialog. Cancel keeps its value; an empty required cell is rejected.

Expected result

Row 2 now says Graph paper and is highlighted as the selected row.

Download this checkpoint source

NATIVE SQUEAK CAPTURE
Edit one cell in native Squeak 6.1
Native Squeak 6.1 checkpoint 02, rendered after executing the exact Workspace block above.

03 · Validate the draft

The same validator handles Add, cell edits, and CSV import. It trims surrounding blanks, validates an actual Gregorian date, bounds text, and converts an amount into integer cents. Parsing the amount examines digits and decimal places; it never evaluates Smalltalk. Text beginning with an equals sign is rejected in the amount column because formulas are outside this app’s scope.

Where to run this

System Browser, LQExpenseBook, instance side. Find the method beginning draftDate:. This excerpt is already installed by checkpoint 03; do not paste a method definition into Workspace.

Construction code · follow the run instructions above
draftDate: dateText category: categoryText description: descriptionText amount: amount
 | cents date category description |
 date := dateText withBlanksTrimmed.
 category := categoryText withBlanksTrimmed.
 description := descriptionText withBlanksTrimmed.
 (io dateFrom: date) ifNil: [status := 'Use a real date: YYYY-MM-DD, years 1900-2100.'. ^ nil].
 (io oneLine: category max: 18) ifFalse: [status := 'Category needs 1-18 printable ASCII characters.'. ^ nil].
 (io oneLine: description max: 48) ifFalse: [status := 'Description needs 1-48 printable ASCII characters.'. ^ nil].
 cents := self centsFrom: amount.
 cents ifNil: [status := 'Amount needs digits and up to two decimals; no signs or formulas.'. ^ nil].
 ^ {date. category. description. cents}

After filing in this checkpoint, evaluate the complete block in Workspace with Do it (Ctrl+D / Cmd+D). It returns the app.

Workspace · run after installing this checkpoint
| app |
app := LQExpenseApp open.
app book editId: 1 column: 5 text: '=SUM(A1)'.
app refresh.
app
  • dateFrom: rejects impossible dates instead of allowing normalization into the following month
  • Category is 1-18 printable ASCII characters and description is 1-48
  • Invalid data updates a status message while preserving records, IDs, selection, and dirty state

Supported dates are 1900-01-01 through 2100-12-31. Amounts are nonnegative digits with zero, one, or two decimal places, up to 9,999,999.99. Currency symbols, commas, exponents, and negative refunds are excluded.

Expected result

The amount formula attempt is rejected, and the original 6.40 remains in row 1.

Download this checkpoint source

NATIVE SQUEAK CAPTURE
Validate the draft in native Squeak 6.1
Native Squeak 6.1 checkpoint 03, rendered after executing the exact Workspace block above.

04 · Exact cents and totals

Decimal currency inputs become integers before they enter a row. Summing 10 and 20 cents produces exactly 30 cents; it never depends on binary floating-point approximations. inject:into: folds the row collection into one accumulator. The display divides whole dollars from the remainder and pads cents to two digits, without changing the underlying value.

Where to run this

System Browser, LQExpenseBook, instance side. Find the method beginning totalCents. This excerpt is already installed by checkpoint 04; do not paste a method definition into Workspace.

Construction code · follow the run instructions above
totalCents
 ^ rows inject: 0 into: [:sum :row | sum + row fifth]

After filing in this checkpoint, evaluate the complete block in Workspace with Do it (Ctrl+D / Cmd+D). It returns the app.

Workspace · run after installing this checkpoint
| app |
app := LQExpenseApp open.
app book editId: 1 column: 5 text: '0.10'.
app book editId: 2 column: 5 text: '0.20'.
app book editId: 3 column: 5 text: '0.00'.
app refresh.
app
  • The accumulator starts at integer zero, so an empty table totals zero
  • row fifth is the integer-cents field
  • The run block changes the three amounts to 0.10, 0.20, and 0.00

The dollar sign is a display convention for this fictional one-currency exercise. There is no currency conversion, tax model, accounting advice, or financial account connection.

Expected result

The total reads $0.30 exactly.

Download this checkpoint source

NATIVE SQUEAK CAPTURE
Exact cents and totals in native Squeak 6.1
Native Squeak 6.1 checkpoint 04, rendered after executing the exact Workspace block above.

05 · Sort without losing identity

Sorting returns a new ordered view of existing records. Numeric amounts compare as integers, dates compare correctly because their fixed-width ISO representation sorts chronologically, and text compares case-sensitively. Clicking a column header selects ascending order; clicking it again reverses direction. Equal values use ascending ID as a deterministic tie-breaker. Sorting never changes the selected ID or the saved row order.

Where to run this

System Browser, LQExpenseBook, instance side. Find the method beginning visibleRows. This excerpt is already installed by checkpoint 05; do not paste a method definition into Workspace.

Construction code · follow the run instructions above
visibleRows
 ^ (rows asSortedCollection: [:a :b | | left right |
  left := a at: sortColumn. right := b at: sortColumn.
  left = right ifTrue: [a first <= b first]
   ifFalse: [ascending ifTrue: [left < right] ifFalse: [left > right]]]) asArray

After filing in this checkpoint, evaluate the complete block in Workspace with Do it (Ctrl+D / Cmd+D). It returns the app.

Workspace · run after installing this checkpoint
| app |
app := LQExpenseApp open.
app book selectId: 2; sortBy: 5.
app refresh.
app
  • left and right are taken from the current sort column
  • Equal sort values use the permanent ID to keep ties predictable
  • A later edit resolves selectedId against stored rows even if the visible order changed

Sorting is a view choice and does not mark the model dirty. CSV preserves insertion order and IDs; it does not save the current sort direction.

Expected result

Amounts sort as 4.25, 6.40, 12.35; the highlighted row is still ID 2.

Download this checkpoint source

NATIVE SQUEAK CAPTURE
Sort without losing identity in native Squeak 6.1
Native Squeak 6.1 checkpoint 05, rendered after executing the exact Workspace block above.

06 · Add and delete rows

Add uses four native request dialogs. Each answer stays in local variables until every prompt completes, so cancelling the last dialog cannot leave an incomplete row in the collection. A valid draft goes through the same model validator as cell editing. Delete acts on the selected ID and asks before removal; a cancelled deletion preserves both selection and data.

Where to run this

System Browser, LQExpenseApp, instance side. Find the method beginning askForRow. This excerpt is already installed by checkpoint 06; do not paste a method definition into Workspace.

Construction code · follow the run instructions above
askForRow
 | date category description amount |
 date := self request: 'Date YYYY-MM-DD' initial: '2026-10-04'. date ifNil: [^ nil].
 category := self request: 'Category' initial: 'Supplies'. category ifNil: [^ nil].
 description := self request: 'Description' initial: ''. description ifNil: [^ nil].
 amount := self request: 'Amount (no currency symbol)' initial: '0.00'. amount ifNil: [^ nil].
 ^ {date. category. description. amount}

After filing in this checkpoint, evaluate the complete block in Workspace with Do it (Ctrl+D / Cmd+D). It returns the app.

Workspace · run after installing this checkpoint
| app |
app := LQExpenseApp open.
app book addDate: '2026-10-04' category: 'Supplies' description: 'Prototype card' amount: '7.50'.
app refresh.
app
  • onCancelReturn: nil is provided by the app request helper
  • The returned four-element array is passed to addDate:category:description:amount:
  • IDs increase after successful additions and are never reused after deletion

Choose a row by clicking its ID before Delete. The table has a ScrollPane, so more rows can be added without resizing the window.

Expected result

A fourth row, Prototype card for 7.50, is selected; the total is $30.50.

Download this checkpoint source

NATIVE SQUEAK CAPTURE
Add and delete rows in native Squeak 6.1
Native Squeak 6.1 checkpoint 06, rendered after executing the exact Workspace block above.

07 · Quote CSV correctly

CSV fields can contain commas and double quotes, so joining strings with commas is not enough. This serializer quotes every field and doubles each embedded quote. The header is fixed and unquoted. Rows are one physical line each, and the parser accepts CR, LF, or CRLF row endings. Printable ASCII field limits exclude multiline fields, tabs, and other control characters. This deliberately bounded dialect is described so importing is predictable.

Where to run this

System Browser, LQExpenseBook, instance side. Find the method beginning serialized. This excerpt is already installed by checkpoint 07; do not paste a method definition into Workspace.

Construction code · follow the run instructions above
serialized
 ^ String streamContents: [:s |
  s nextPutAll: 'id,date,category,description,amount'; cr.
  rows do: [:row | s nextPutAll: (io csvLine: {row first printString. row second. row third. row fourth. self money: row fifth}); cr]]

After filing in this checkpoint, evaluate the complete block in Workspace with Do it (Ctrl+D / Cmd+D). It returns the app.

Workspace · run after installing this checkpoint
| app |
app := LQExpenseApp open.
app book editId: 2 column: 4 text: 'Paper, "pens"'.
app book status: 'CSV doubles quotes inside quoted fields. Inspect CSV shows the complete text.'.
app refresh.
app
  • csvLine: quotes every value, including IDs and amounts
  • quote: turns one literal quote into two quotes inside a quoted field
  • parseLine: uses start, plain, quoted, and closed states and rejects text after a closing quote

The parser accepts quoted or unquoted fields, empty fields at the syntax level, and doubled quotes. Model validation still rejects empty required cells. It rejects unmatched quotes, quote characters inside unquoted fields, malformed IDs, duplicate IDs, and extra columns. The text is never evaluated.

Expected result

Row 2 displays Paper, "pens"; Inspect CSV opens a native Inspector on the serialized string.

Download this checkpoint source

NATIVE SQUEAK CAPTURE
Quote CSV correctly in native Squeak 6.1
Native Squeak 6.1 checkpoint 07, rendered after executing the exact Workspace block above.

08 · Save and load snapshots

Import first checks the exact five-column header and then builds a temporary collection. Every ID must be positive, at most nine digits, and unique. Every data field passes the same validator as interactive editing. A bad last row returns before the final assignment, preserving the current table. Save creates a new snapshot through a temporary sibling file and refuses an existing destination file or directory.

Where to run this

System Browser, LQExpenseBook, instance side. Find the method beginning importCSV:. This excerpt is already installed by checkpoint 08; do not paste a method definition into Workspace.

Construction code · follow the run instructions above
importCSV: text replaceUnsaved: confirmed
 | input temporary fields id draft largest |
 text ifNil: [status := 'Read failed or cancelled. Table kept.'. ^ false].
 (dirty and: [confirmed not]) ifTrue: [status := 'Import cancelled. Unsaved table kept.'. ^ false].
 input := text readStream.
 input nextLine = 'id,date,category,description,amount' ifFalse: [status := 'Wrong CSV header. Table kept.'. ^ false].
 temporary := OrderedCollection new. largest := 0.
 [input atEnd] whileFalse: [
  fields := io parseLine: input nextLine.
  (fields isNil or: [fields size ~= 5]) ifTrue: [status := 'Malformed CSV row. Table kept.'. ^ false].
  ((io digits: fields first) and: [fields first size <= 9]) ifFalse: [status := 'Bad row ID. Table kept.'. ^ false].
  id := fields first asNumber.
  (id < 1 or: [temporary anySatisfy: [:row | row first = id]]) ifTrue: [status := 'Invalid or duplicate ID. Table kept.'. ^ false].
  draft := self draftDate: fields second category: fields third description: fields fourth amount: fields fifth.
  draft ifNil: [^ false].
  temporary add: ({id}, draft). largest := largest max: id].
 rows := temporary. nextId := largest + 1. selectedId := nil. dirty := false.
 status := 'All CSV rows validated, then committed together.'.
 ^ true

After filing in this checkpoint, evaluate the complete block in Workspace with Do it (Ctrl+D / Cmd+D). It returns the app.

Workspace · run after installing this checkpoint
| app path |
app := LQExpenseApp open.
path := FileDirectory default fullNameFor: 'lq-expenses-', UUID new asString, '.csv'.
(app book saveNewTo: path) ifFalse: [self error: 'Snapshot save failed'].
(app book loadFrom: path replaceUnsaved: false) ifFalse: [self error: 'Snapshot load failed'].
app refresh.
app
  • temporary is separate from rows until the entire file is valid
  • nextId becomes one larger than the greatest imported ID
  • dirty becomes false only after a successful save or complete import

The run writes a new lq-expenses-UUID.csv beside the image on each execution. The UI asks before replacing unsaved data on Open. Save never overwrites a prior snapshot. Ordinary write/install failures clean up temporary bytes and preserve dirty state; simultaneous writers and crash-proof durability are outside this example.

Expected result

A uniquely named CSV snapshot is written and loaded; the original three rows are intact.

Download this checkpoint source

NATIVE SQUEAK CAPTURE
Save and load snapshots in native Squeak 6.1
Native Squeak 6.1 checkpoint 08, rendered after executing the exact Workspace block above.

09 · A complete expense table

The app is a SystemWindow model. Its normal close action asks okToClose; a clean table closes immediately, while a dirty one asks whether to discard. Cancelling keeps the window and records intact. The final tests combine model invariants with app-level cancellation, fixed sizing, and window closing, so the guard is tested through the actual SystemWindow path.

Where to run this

System Browser, LQExpenseApp, instance side. Find the method beginning okToClose. This excerpt is already installed by checkpoint 09; do not paste a method definition into Workspace.

Construction code · follow the run instructions above
okToClose
 ^ book isDirty not or: [self confirm: 'Close and discard unsaved tutorial data?']

After filing in this checkpoint, evaluate the complete block in Workspace with Do it (Ctrl+D / Cmd+D). It returns the app.

Workspace · run after installing this checkpoint
| app |
app := LQExpenseApp open.
app book selectId: 2; sortBy: 3.
app book editId: 2 column: 5 text: '13.75'.
app refresh.
app
  • isDirty is true after successful additions, edits, and deletions
  • A failed save never clears dirty
  • The example changes row 2 after sorting by category, demonstrating identity through a view change

Save a new snapshot before closing if you want to keep your fictional data. Direct developer deletion can bypass normal application safeguards. This app has no formulas, undo history, multiple sheets, or external account access.

Expected result

ID 2 is highlighted after its amount becomes 13.75; the new total is $24.40.

Download this checkpoint source

NATIVE SQUEAK CAPTURE
A complete expense table in native Squeak 6.1
Native Squeak 6.1 checkpoint 09, rendered after executing the exact Workspace block above.

Watch the workflow

These are real Squeak 6.1 Morphic renders. The demonstrations replay app messages; they are not screen recordings of a person typing. Each poster is the first native frame of its matching GIF.

NATIVE SQUEAK CAPTURE
Build an editable expense table demonstration
Native scripted frames: edit a cell, sort amounts, then edit the same permanent row ID in its new position.
NATIVE SQUEAK CAPTURE
Build an editable expense table demonstration
Native scripted frames: reject an invalid edit, cancel a cell edit, save a new snapshot, then load it.

Practice with tested solutions

1. Add a fractional expense

Add a fourth fictional expense for 0.05 and prove that the total becomes exactly 2305 cents.

Show a tested solution

File in the final app source, then evaluate this exact complete Workspace block with Do it. The assertion is part of the solution.

Exercise solution
| app |
app := LQExpenseApp open.
app book addDate: '2026-10-04' category: 'Supplies' description: 'Tiny label' amount: '0.05'.
app book totalCents = 2305 ifFalse: [self error: 'Unexpected total'].
app refresh.
app
Expected

Four rows, a total of $23.05, and no assertion failure.

Download complete exercise solution

The input becomes integer 5, so the total is an exact integer sum.

This exact block was executed in the reference image; the harness also checked the returned model state.

2. Edit the same row after sorting

Sort by amount, then change the description of ID 2. Prove that row identity survives the reordered view.

Show a tested solution

File in the final app source, then evaluate this exact complete Workspace block with Do it. The assertion is part of the solution.

Exercise solution
| app |
app := LQExpenseApp open.
app book selectId: 2; sortBy: 5.
app book editId: 2 column: 4 text: 'Sorted but still row two'.
((app book rowId: 2) fourth = 'Sorted but still row two' and: [app book selectedId = 2]) ifFalse: [self error: 'Wrong row edited'].
app refresh.
app
Expected

The last visible row remains ID 2 and receives the replacement description.

Download complete exercise solution

Store identity independently from display position. Numeric sorting does not rewrite the IDs.

This exact block was executed in the reference image; the harness also checked the returned model state.

3. Prove a bad import is transactional

Append an invalid amount in a later CSV row and assert that importing it preserves every current record.

Show a tested solution

File in the final app source, then evaluate this exact complete Workspace block with Do it. The assertion is part of the solution.

Exercise solution
| app before accepted bad |
app := LQExpenseApp open.
before := app book rows.
bad := app book serialized, '4,2026-10-04,Food,Lunch,not-money', String cr.
accepted := app book importCSV: bad replaceUnsaved: true.
(accepted not and: [app book rows = before]) ifFalse: [self error: 'Bad import mutated data'].
app refresh.
app
Expected

The original three rows remain, with an amount-validation message.

Download complete exercise solution

Valid earlier rows were added only to a temporary collection, so rejecting the last row is safe.

This exact block was executed in the reference image; the harness also checked the returned model state.

When something looks wrong

A method gives a syntax error in Workspace

File in the complete checkpoint. Method definitions belong on the named class and side in System Browser. Only the separate run block belongs in Workspace.

Save refuses my filename

Choose a new name in an existing writable folder. The snapshot writer refuses existing files and directories; it never replaces them.

The table or appointment list looks stale after a Workspace edit

Send refresh to the app after changing its book. Native buttons do this automatically.

Verification, cleanup and next steps

Every displayed method excerpt was recompiled in its named class. Every exact Workspace stage and exercise solution was executed in Squeak 6.1. Screenshots and GIF frames come from native Morphic window imageForm renders, produced by scripted messages to the running apps.

35 SUnit tests passed in Squeak 6.1 with zero failures and errors. Nine independently loaded checkpoints, nine method excerpts, nine exact run blocks, and three exact exercise solutions were also executed.

Close tutorial windows through their close boxes. Keep source and useful snapshots separately from your image. If you remove practice snapshots later, delete only the lq-expenses-UUID.csv or lq-calendar-UUID.csv files that this lesson created.

  • Official Squeak 6.1 download
  • Shipped Squeak 6.1 image source — Date, SystemWindow, ScrollPane, SimpleButtonMorph, FileDirectory, FileStream, and SUnit inspected and exercised in the reference image.

Explore more working examples · Return to the learning path

Scope of this example

  • Single-user fictional practice data; no network, account connection, or private user data.
  • Printable ASCII and one-line CSV fields only; these limits are explicit validator rules, not general CSV limitations.
  • Create-only snapshots handle ordinary errors but make no claim of crash-proof durability or coordinated simultaneous writes.