Architecture Decisions
\n"); + html.push_str( + "Key design decisions with context, alternatives considered, \ + and consequences.
\n", + ); + html.push_str("- \n");
+ for adr in adrs {
+ let _ = writeln!(
+ html,
+ "
- {num} — {title} ", + file = adr.output_file, + num = html_escape(&adr.number), + title = html_escape(&adr.title), + ); + } + html.push_str("
Architecture Decisions
\n"); + html.push_str( + "Key design decisions — context, alternatives considered, and consequences.
\n", + ); + html.push_str("\n"); + // Prose docs cards for &(_, file, title) in prose_pages { let (emoji, desc) = landing_card_meta(file); diff --git a/docs/beamtalk-language-features.md b/docs/beamtalk-language-features.md index b894e529d..a2d565ec6 100644 --- a/docs/beamtalk-language-features.md +++ b/docs/beamtalk-language-features.md @@ -4,7 +4,7 @@ Planned language features for beamtalk. See [beamtalk-principles.md](beamtalk-pr **Status:** Active development — implemented features are stable; planned sections are marked inline. -**Syntax note:** Beamtalk uses a cleaned-up Smalltalk syntax: `//` comments (not `"..."`), standard math precedence (not left-to-right), and optional statement terminators (newlines work). +**Syntax note:** Beamtalk uses a modernised Smalltalk syntax: `//` comments (not `"..."`), standard math precedence (not left-to-right), and optional statement terminators (newlines work). --- @@ -160,7 +160,7 @@ Actor subclass: Counter ProtoObject (minimal - identity, DNU) └─ Object (reflection + new) ├─ Integer, String (primitives) - ├─ Value (immutable value objects - ADR 0042) + ├─ Value (immutable value objects) │ └─ Point, Color (value types) └─ Actor (process-based + spawn) └─ Counter, Server (actors) @@ -801,16 +801,25 @@ Pattern matching can bind variables in match arms: Hot code reload via message sends — no dedicated `patch` syntax needed. ```beamtalk -// Replace a method on a running class +// Canonical Counter (already running in the workspace) +Actor subclass: Counter + state: value = 0 + increment => self.value := self.value + 1 + getValue => self.value + +// Replace a single method — existing instances pick it up immediately Counter >> increment => Telemetry log: "incrementing" self.value := self.value + 1 -// Redefine a class to update all future instances +// Redefine the class to add state — new instances get the updated shape Actor subclass: Counter - state: value = 0, lastModified = nil - increment => self.value := self.value + 1 - getValue => ^self.value + state: value = 0 + state: lastModified = nil + increment => + self.value := self.value + 1 + self.lastModified := DateTime now + getValue => self.value ``` --- @@ -1297,95 +1306,4 @@ The full list of structural intrinsics: `actorSpawn`, `actorSpawnWith`, `blockVa --- -## Tooling - -Tooling is part of the language, not an afterthought. Beamtalk is designed to be used interactively. - -### CLI Tools - -```bash -# Project management -beamtalk new myapp # Create new project -beamtalk build # Compile to BEAM -beamtalk run # Compile and start -beamtalk check # Check for errors without compiling -beamtalk daemon start/stop # Manage compiler daemon - -# Development -beamtalk repl # Interactive REPL -``` - -### REPL Features - -```beamtalk -// Spawn and interact -counter := Counter spawn -counter increment -counter getValue // => 1 -``` - -### VS Code Extension - -The [Beamtalk VS Code extension](https://github.com/jamesc/beamtalk/tree/main/editors/vscode) provides: - -- Syntax highlighting for `.bt` files -- Language Server Protocol (LSP) integration -- Error diagnostics with source spans - -### Testing Framework - -Beamtalk includes a native test framework inspired by Smalltalk's SUnit. - -```beamtalk -// stdlib/test/counter_test.bt - -TestCase subclass: CounterTest - - testInitialValue => - self assert: (Counter spawn getValue) equals: 0 - - testIncrement => - self assert: (Counter spawn increment) equals: 1 - - testMultipleIncrements => - counter := Counter spawn - 3 timesRepeat: [counter increment] - self assert: (counter getValue) equals: 3 -``` - -Each test method gets a fresh instance with `setUp` → test → `tearDown` lifecycle. - -#### Assertion Methods - -| Method | Description | Example | -|--------|-------------|---------| -| `assert:` | Assert condition is true | `self assert: (x > 0)` | -| `assert:equals:` | Assert two values are equal | `self assert: result equals: 42` | -| `deny:` | Assert condition is false | `self deny: list isEmpty` | -| `should:raise:` | Assert block raises error | `self should: [1 / 0] raise: #badarith` | -| `fail:` | Unconditional failure | `self fail: "not implemented"` | - -#### Running Tests - -```bash -beamtalk test -``` - -#### REPL Integration - -Run tests interactively from the REPL using either `:` shortcuts or native message sends: - -```text -> :load stdlib/test/counter_test.bt -Loaded CounterTest - -> :test CounterTest -Running 1 test class... - ✓ testIncrement - ✓ testMultipleIncrements -2 passed, 0 failed - -// Equivalent native API — works from compiled code too: -> (Workspace test: CounterTest) failed -// => 0 -``` +See [Tooling](beamtalk-tooling.md) for CLI tools, REPL, VS Code extension, and testing framework. diff --git a/docs/beamtalk-tooling.md b/docs/beamtalk-tooling.md new file mode 100644 index 000000000..20f3e1e86 --- /dev/null +++ b/docs/beamtalk-tooling.md @@ -0,0 +1,87 @@ +# Tooling + +Tooling is part of the language, not an afterthought. Beamtalk is designed to be used interactively. + +## CLI Tools + +```bash +# Project management +beamtalk new myapp # Create new project +beamtalk build # Compile to BEAM +beamtalk run # Compile and start +beamtalk check # Check for errors without compiling +beamtalk daemon start/stop # Manage compiler daemon + +# Development +beamtalk repl # Interactive REPL +beamtalk test # Run test suite +``` + +## REPL Features + +```beamtalk +// Spawn and interact +counter := Counter spawn +counter increment +counter getValue // => 1 +``` + +## VS Code Extension + +The [Beamtalk VS Code extension](https://github.com/jamesc/beamtalk/tree/main/editors/vscode) provides: + +- Syntax highlighting for `.bt` files +- Language Server Protocol (LSP) integration +- Error diagnostics with source spans + +## Testing Framework + +Beamtalk includes a native test framework inspired by Smalltalk's SUnit. + +```beamtalk +// stdlib/test/counter_test.bt + +TestCase subclass: CounterTest + + testInitialValue => + self assert: (Counter spawn getValue) equals: 0 + + testIncrement => + self assert: (Counter spawn increment) equals: 1 + + testMultipleIncrements => + counter := Counter spawn + 3 timesRepeat: [counter increment] + self assert: (counter getValue) equals: 3 +``` + +Each test method gets a fresh instance with `setUp` → test → `tearDown` lifecycle. + +### Assertion Methods + +| Method | Description | Example | +|--------|-------------|---------| +| `assert:` | Assert condition is true | `self assert: (x > 0)` | +| `assert:equals:` | Assert two values are equal | `self assert: result equals: 42` | +| `deny:` | Assert condition is false | `self deny: list isEmpty` | +| `should:raise:` | Assert block raises error | `self should: [1 / 0] raise: #badarith` | +| `fail:` | Unconditional failure | `self fail: "not implemented"` | + +### REPL Integration + +Run tests interactively from the REPL using either `:` shortcuts or native message sends: + +```text +> :load stdlib/test/counter_test.bt +Loaded CounterTest + +> :test CounterTest +Running 1 test class... + ✓ testIncrement + ✓ testMultipleIncrements +2 passed, 0 failed + +// Equivalent native API — works from compiled code too: +> (Workspace test: CounterTest) failed +// => 0 +``` diff --git a/stdlib/src/README.md b/stdlib/src/README.md index 934675fdf..09e4d844b 100644 --- a/stdlib/src/README.md +++ b/stdlib/src/README.md @@ -2,52 +2,6 @@ Copyright 2026 James Casey SPDX-License-Identifier: Apache-2.0 --> -# Beamtalk Standard Library - The standard library for Beamtalk, where everything is a message send. -## Class Hierarchy - -```text -ProtoObject (minimal root - identity, DNU) - └─ Object (value types - reflection, nil testing) - ├─ Integer, Float, String, Atom (sealed primitives) - ├─ True, False, Nil (sealed primitives) - ├─ Block (closures) - ├─ Collection (abstract) - │ ├─ SequenceableCollection - │ │ ├─ Array (Erlang tuple) - │ │ └─ List (Erlang list) - │ ├─ Set (ordsets) - │ └─ Dictionary (Erlang map) - ├─ Beamtalk (system reflection) - └─ Actor (process-based) - └─ (user actors: Counter, Worker, etc.) -``` - -See each `.bt` file for full API documentation and usage examples. - -## BEAM Mapping - -| Beamtalk | Erlang/BEAM | Has Process? | -|----------|-------------|--------------| -| `ProtoObject` | Abstract root | — | -| `Object` | Value type root | ❌ | -| `Actor` | `gen_server` process | ✅ | -| `Integer` | Erlang integer | ❌ | -| `Float` | Erlang float | ❌ | -| `True` / `False` | Atoms `true` / `false` | ❌ | -| `Nil` | Atom `nil` | ❌ | -| `Atom` | Erlang atom | ❌ | -| `Block` | Anonymous fun (closure) | ❌ | -| `String` | Binary `<<"UTF-8">>` | ❌ | -| `Array` | Erlang tuple `{...}` | ❌ | -| `List` | Erlang list `[...]` | ❌ | -| `Set` | `ordsets` (sorted list) | ❌ | -| `Dictionary` | Erlang map `#{...}` | ❌ | - -## Design - -- [Object Model](../docs/beamtalk-object-model.md) — class hierarchy and metaclasses -- [Design Principles](../docs/beamtalk-principles.md) — philosophy and rationale -- [Language Features](../docs/beamtalk-language-features.md) — full syntax specification +See each class page for full API documentation and usage examples.