17. Stdlib

Level: beginner · Reading time: 22 min · Prerequisite: book/chapters/16a-vitte-binding.html · Track: essential · Maturity: reviewed · Last review: 2026-05-09

TL;DR (5 lines)

  • Stdlib families exist to separate responsibilities.
  • A complete scenario teaches more than a flat catalog.
  • Validation and transport should stay apart.
  • Family boundaries matter in docs as much as in code.
  • The chapter should scale to the whole library tree.

Frequent mistakes

  • Listing module names without explaining responsibility.
  • Reducing stdlib docs to hello-world snippets.
  • Mixing host interaction and pure domain logic in one explanation.

Prerequisites: book/chapters/16a-vitte-binding.html. See also: book/chapters/16a-vitte-binding.html, book/chapters/27-grammar.html, book/chapters/31-build-errors.html.

Concrete Problem

Readers often see stdlib pages as catalogs with no architectural guidance, so they cannot place new code correctly.

Red Thread (Single Project)

One small application flow uses pure helpers, path normalization, and summary rendering while naming which library family owns each concern.

For what

This chapter helps the reader classify library work by family and responsibility.

Work in this chapter

You will inspect one complete flow, then map its responsibilities to stdlib families and compare it to an invalid domain variant.

Coherent example

space demo/stdlib

form Manifest {
  name: string
  root_path: string
  targets: int
}

pick Plan {
  case Ready(summary: string),
  case Invalid(code: int),
}

proc normalize_root(root_path: string) -> string {
  if root_path == "" { give "." }
  give root_path
}

proc validate_manifest(m: Manifest) -> Plan {
  if m.name == "" { give Plan.Invalid(11) }
  if m.targets <= 0 { give Plan.Invalid(12) }
  give Plan.Ready(m.name)
}

Complete examples

Each block below is a complete reading unit with its own boundary, data shape, and observable result.

Primary coherent example

This is the compact chapter anchor used by the surrounding explanation.

space demo/stdlib

form Manifest {
  name: string
  root_path: string
  targets: int
}

pick Plan {
  case Ready(summary: string),
  case Invalid(code: int),
}

proc normalize_root(root_path: string) -> string {
  if root_path == "" { give "." }
  give root_path
}

proc validate_manifest(m: Manifest) -> Plan {
  if m.name == "" { give Plan.Invalid(11) }
  if m.targets <= 0 { give Plan.Invalid(12) }
  give Plan.Ready(m.name)
}

Separate domain and library helper

This flow keeps pure validation apart from utility-style normalization.

space examples/stdlib/manifest

form Manifest {
  name: string
  root: string
}

proc normalize_root(root: string) -> string {
  if root == "" { give "." }
  give root
}

proc validate_manifest(m: Manifest) -> int {
  if m.name == "" { give 11 }
  let root: string = normalize_root(m.root)
  give 0
}

export *

Classify library responsibility

This block keeps transformation local before any runtime-facing effect.

space examples/stdlib/classify

proc trim_code(code: int) -> int {
  if code < 0 { give 0 }
  give code
}

proc render_status(code: int) -> string {
  if code == 0 { give "ok" }
  give "error"
}

proc main(args: list[string]) -> int {
  let code: int = trim_code(0)
  give code
}

export *

Immediate work for this chapter

  • Classify each helper by responsibility: core, collection, transform, I/O, runtime.
  • Keep pure domain logic separate from runtime-facing effects.
  • Use examples that scale to the library family, not only one call.
  • Keep the first code block complete and aligned with current Vitte docs syntax.
  • Keep the invalid block focused on one broken contract only.
  • Replace generic prose with one concrete rule visible in the code.
  • Keep every example small enough to review from top to bottom.

Chapter override: 17-stdlib.html

Dedicated problem

17. Stdlib needs a concrete production-grade anchor around domain logic, library helper, and runtime-facing effect. The page should keep the examples, diagnostics, and review rules tied to that exact boundary instead of drifting back to generic tutorial prose.

Specific complete examples

17. Stdlib chapter anchor

The primary example is promoted here as the first chapter-specific production reading unit.

space demo/stdlib

form Manifest {
  name: string
  root_path: string
  targets: int
}

pick Plan {
  case Ready(summary: string),
  case Invalid(code: int),
}

proc normalize_root(root_path: string) -> string {
  if root_path == "" { give "." }
  give root_path
}

proc validate_manifest(m: Manifest) -> Plan {
  if m.name == "" { give Plan.Invalid(11) }
  if m.targets <= 0 { give Plan.Invalid(12) }
  give Plan.Ready(m.name)
}

Separate domain and library helper

This flow keeps pure validation apart from utility-style normalization.

space examples/stdlib/manifest

form Manifest {
  name: string
  root: string
}

proc normalize_root(root: string) -> string {
  if root == "" { give "." }
  give root
}

proc validate_manifest(m: Manifest) -> int {
  if m.name == "" { give 11 }
  let root: string = normalize_root(m.root)
  give 0
}

export *

Classify library responsibility

This block keeps transformation local before any runtime-facing effect.

space examples/stdlib/classify

proc trim_code(code: int) -> int {
  if code < 0 { give 0 }
  give code
}

proc render_status(code: int) -> string {
  if code == 0 { give "ok" }
  give "error"
}

proc main(args: list[string]) -> int {
  let code: int = trim_code(0)
  give code
}

export *

Risks and diagnostics

RiskDiagnostic signalAction
Boundary driftThe chapter loses sight of domain logic, library helper, and runtime-facing effect.Restate the boundary beside the first code block and every invalid case.
Generic proseA paragraph would still be true in another chapter.Replace it with a code-specific rule from this page.
Weak diagnosticThe failure does not point back to the chapter contract.Reduce the invalid case until one failure explains the rule.

Review checklist

  • The first example is complete and aligned with Vitte docs syntax.
  • The production section names where this construct belongs in real code.
  • The risk table connects each failure to a diagnostic or review action.
  • The avoid list rejects broad misuse without adding quiz-like prompts.

Production use

  • Use this chapter when a code review needs to preserve domain logic, library helper, and runtime-facing effect.
  • Keep examples small enough to copy into fixtures or docs smoke tests.
  • Treat the invalid case as regression material for future docs checks.

What to avoid

  • Do not add a second topic that hides the chapter's main contract.
  • Do not expand examples by adding unrelated subsystems.
  • Do not rely on prose when a small Vitte block can show the rule.

Global explanation

The stdlib should be taught by ownership. Core helpers, collections, data transforms, path and I/O boundaries, JSON, concurrency, and runtime-facing families all solve different problems. The chapter is useful only if the reader can classify future code with it.

Invalid case

proc main(args: list[string]) -> int {
  let manifest: Manifest = Manifest { name: "", root_path: "", targets: 0 }
  give 0
}

This invalid case is intentionally small. It exists to isolate the contract failure that the chapter is trying to teach.

Common pitfalls

  • Listing module names without explaining responsibility.
  • Reducing stdlib docs to hello-world snippets.
  • Mixing host interaction and pure domain logic in one explanation.

Short exercise

Take the example and say which future step would belong to `json`, which to `io`, and which should remain in pure domain code.

Summary in 5 points

  1. Stdlib families exist to separate responsibilities.
  2. A complete scenario teaches more than a flat catalog.
  3. Validation and transport should stay apart.
  4. Family boundaries matter in docs as much as in code.
  5. The chapter should scale to the whole library tree.

See also

Next best action

Extend the coherent example by one small, justified step and keep the same contract visible from input to output.

Chapter deep dive

17. Stdlib classifies library families by responsibility. The chapter is written for a reader deciding whether code belongs in stdlib or application space.

The practical boundary is: domain logic, library helper, and runtime-facing effect. Keep that boundary in view while reading the example, the invalid case, and the exercise.

Role in the learning path

Readers often see stdlib pages as catalogs with no architectural guidance, so they cannot place new code correctly.

One small application flow uses pure helpers, path normalization, and summary rendering while naming which library family owns each concern.

This chapter helps the reader classify library work by family and responsibility.

Profile-specific deep dive

Family responsibility

  • Core helpers, collections, transforms, I/O, and runtime edges solve different problems.
  • The example should show which family owns which step.
  • Do not mix pure validation with host effects in the same explanation.

Catalog usefulness

  • A stdlib chapter should help classify future code.
  • Examples should scale from one helper to a family rule.
  • References should point to modules that reinforce ownership.

Reading the valid example

  1. space demo/stdlib: names the ownership boundary before any behavior appears.
  2. form Manifest {: introduces a data contract that later branches can rely on.
  3. name: string: supports the chapter contract without adding hidden behavior.
  4. root_path: string: supports the chapter contract without adding hidden behavior.
  5. targets: int: supports the chapter contract without adding hidden behavior.
  6. }: supports the chapter contract without adding hidden behavior.
  7. pick Plan {: makes possible outcomes explicit instead of encoding them as magic values.
  8. case Ready(summary: string),: names one outcome that callers must be ready to handle.
  9. case Invalid(code: int),: names one outcome that callers must be ready to handle.
  10. }: supports the chapter contract without adding hidden behavior.
  11. proc normalize_root(root_path: string) -> string {: states the callable contract: inputs first, result shape last.
  12. if root_path == "" { give "." }: guards a failure or edge case before the nominal result.
  13. give root_path: ends the local path with an explicit result.
  14. }: supports the chapter contract without adding hidden behavior.
  15. proc validate_manifest(m: Manifest) -> Plan {: states the callable contract: inputs first, result shape last.
  16. if m.name == "" { give Plan.Invalid(11) }: guards a failure or edge case before the nominal result.
  17. if m.targets <= 0 { give Plan.Invalid(12) }: guards a failure or edge case before the nominal result.
  18. give Plan.Ready(m.name): ends the local path with an explicit result.
  19. }: supports the chapter contract without adding hidden behavior.

Lesson from the invalid example

  1. proc main(args: list[string]) -> int {: this line helps isolate the failure because it states the callable contract: inputs first, result shape last.
  2. let manifest: Manifest = Manifest { name: "", root_path: "", targets: 0 }: this line helps isolate the failure because it keeps an intermediate decision visible for review.
  3. give 0: this line helps isolate the failure because it ends the local path with an explicit result.
  4. }: this line helps isolate the failure because it supports the chapter contract without adding hidden behavior.

Engineering decisions to preserve

  • Name the boundary before changing code: Stdlib families exist to separate responsibilities.
  • Keep the smallest example executable: A complete scenario teaches more than a flat catalog.
  • Make the invalid path explain one failure only: Validation and transport should stay apart.
  • Prefer a visible contract over an implied convention: Family boundaries matter in docs as much as in code.
  • Leave a review anchor that another maintainer can verify: The chapter should scale to the whole library tree.

Context-specific review criteria

  • The page makes the domain logic, library helper, and runtime-facing effect boundary visible before the first code block.
  • The intended reader, a reader deciding whether code belongs in stdlib or application space, can follow the valid example through named contracts instead of memorized tokens.
  • The invalid example fails for the same reason the prose discusses.
  • The exercise extends the same contract instead of introducing an unrelated concept.
  • The next chapter can reuse the vocabulary introduced here without redefining it.
  • The chapter stays specific enough that its title materially changes the meaning of the page.
  • Every warning connects to a concrete code shape.
  • The summary leaves one durable engineering rule behind.

Contract matrix

ConcernChapter ruleEvidence to keep
OwnershipCode belongs behind the boundary named by the chapter.The chapter keeps ownership visible through domain logic, library helper, and runtime-facing effect.
Input contractThe procedure receives a shape that is named before branching.The valid example names the accepted shape before branching.
Nominal pathThe clean path remains readable without hidden state.The successful result can be found without reading hidden state.
Failure pathThe invalid case isolates one failure reason.The broken example has one main reason to fail.
NamingNames explain the domain rather than only the mechanism.Names remain tied to the chapter goal.
TypesTypes remove ambiguity from values and results.Fields and return values carry domain meaning.
Control flowBranches stay traceable from guard to result.Guards appear before the result they protect.
Module boundaryThe public surface stays smaller than implementation detail.The public surface remains smaller than the implementation detail.
Diagnostic valueThe failure path points back to the exact contract.The invalid example points back to the exact contract.
Test valueRegression evidence covers one passing path and one failing path.One passing case and one failing case cover the lesson.
Refactor valueImplementation cleanup preserves the result shape.The result shape stays stable during local cleanup.
Publication valueThe chapter leaves one concrete engineering rule.The chapter leaves one concrete engineering rule.

Rewrite path for this chapter

  1. Rewrite the opening paragraph so it names domain logic, library helper, and runtime-facing effect before naming syntax.
  2. Keep the valid example small enough that the full contract fits on screen.
  3. Move any broad claim back to a specific line in the example.
  4. Preserve one invalid case that fails for the chapter's main reason.
  5. Add one sentence explaining why the invalid case is not a random error.
  6. Make every pitfall actionable by naming the code shape it damages.
  7. Keep the exercise inside the same domain as the example.
  8. Avoid introducing a second unrelated project just to show variety.
  9. Use the summary to restate the chapter rule, not the table of contents.
  10. Check that the next chapter can build on this vocabulary.
  11. Remove any sentence that would still be true in every other chapter.
  12. Keep the last action small, local, and testable.

Diagnostic anchors

  • The first inspected line is the one that declares the chapter's main contract.
  • The central type, field, procedure, or branch carries the chapter's main idea.
  • The invalid example includes a sentence-level explanation of its failure.
  • Refactors preserve the detail that would otherwise mislead a future reader.
  • The behavior that must stay stable is named before implementation changes begin.
  • Vague names are replaced before they become review friction.
  • Regression coverage protects the chapter's main contract.
  • Implementation details stay out of public API unless the chapter explicitly teaches that surface.
  • Beginner-facing diagnostics point to the contract, not to a random syntax detail.
  • The next chapter can assume one clearly named concept from this page.

When extending this chapter

  • Extend toward a reader deciding whether code belongs in stdlib or application space, not toward a broader catalog of features.
  • Add a second example only if it sharpens the same contract.
  • Prefer a small variant over a new subsystem.
  • Keep prose close to code; every abstract claim should point to a visible shape.
  • Do not hide a new concept in the exercise.
  • If a paragraph explains policy, add the concrete code boundary it protects.
  • If a paragraph explains syntax, add the semantic reason the syntax matters.
  • If a paragraph explains architecture, identify the owner of each boundary.
  • If a paragraph explains failure, keep the failing line close to the explanation.
  • Stop expanding when the chapter has one complete, testable lesson.

Failure modes to avoid

  • Listing module names without explaining responsibility.
  • Reducing stdlib docs to hello-world snippets.
  • Mixing host interaction and pure domain logic in one explanation.

Practice scenario

Start from the coherent example in 17. Stdlib. Change one identifier, one guard, and one returned value. After each change, write down whether the public contract is still the same contract or a new one.

If the contract changed, update the type or result shape first. If only the implementation changed, keep the external name stable and add one regression note explaining what should not change again.

Before moving on

  • You can state the chapter role: classifies library families by responsibility.
  • You can point to the main boundary: domain logic, library helper, and runtime-facing effect.
  • You can connect the invalid case to the problem statement: Readers often see stdlib pages as catalogs with no architectural guidance, so they cannot place new code correctly.
  • You can perform the exercise: Take the example and say which future step would belong to `json`, which to `io`, and which should remain in pure domain code.