Contents Open

Documentation

The Sable Programming Language

The book about Sable: a tour to read in one sitting, a guide that teaches the language from the ground up, and a reference that states every rule. Read it in order, or jump to what you need.

Welcome to Sable

Start here: what Sable is, how to install it, and a quick tour of the whole language.

  1. 1.1About SableWhat Sable is for, the ideas it is built on, and what it deliberately leaves out.
  2. 1.2Getting StartedBuild the toolchain, run a file, make a package, and set up your editor.
  3. 1.3A Sable TourThe whole language in one sitting: enough of every feature to start writing programs.

Language Guide

The language one idea at a time, from constants and variables to memory, concurrency and interop. Each chapter builds on the ones before it.

  1. 2.1The BasicsConstants and variables, the built-in types, type inference, tuples, optionals and assertions.
  2. 2.2Basic OperatorsArithmetic, overflow and wrapping, comparison, logic, ranges, and how operators bind.
  3. 2.3Strings and CharactersString literals, interpolation and format specs, Unicode, indices and substrings.
  4. 2.4Arrays and CollectionsThe array family, slices, ranges as places, dictionaries, and the library collections.
  5. 2.5Control Flowif and guard, loops, labels, defer and using, and switch.
  6. 2.6FunctionsLabels, defaults, variadics, inout and out parameters, overloading, generators and function types.
  7. 2.7ClosuresClosure syntax, trailing closures, captures and capture lists, escaping and autoclosures.
  8. 2.8Structures and ClassesValues and objects: record literals, memberwise initialisers, identity and inheritance.
  9. 2.9PropertiesStored and computed properties, observers, field-backed accessors, lazy and static properties.
  10. 2.10Methods, Subscripts and OperatorsInstance and static methods, mutating methods, subscripts, and overloading operators.
  11. 2.11Initialization and DeinitializationInitialisers, delegation, required and convenience initialisers, failing safely, and deinit.
  12. 2.12Enums and UnionsNamed integers and flag sets, tagged unions with payloads, and structural unions.
  13. 2.13Pattern Matchingmatch as a statement and an expression, every pattern form, guards and exhaustiveness.
  14. 2.14Optionalsnone, optional binding, chaining, defaults, force-unwrapping and narrowing.
  15. 2.15Error HandlingTyped throws, try and its forms, do-catch, rethrows, throwing iteration and panics.
  16. 2.16ProtocolsRequirements, associated types, default implementations, some and any, and composition.
  17. 2.17GenericsGeneric functions and types, constraints and where clauses, specialisation and variance.
  18. 2.18ExtensionsAdding members and conformances, constrained extensions, and extending every array.
  19. 2.19Casting, Metatypes and ReflectionCasts and type tests, key paths, types as values, opening existentials, and reflection.
  20. 2.20Concurrencyasync and await, structured tasks, cancellation, actors, Sendable and threads.
  21. 2.21Memory and OwnershipThe three tiers, reference counting, move-only types, exclusivity, references and regions.
  22. 2.22Inline LayoutContiguous pointer-free values, relative references, variant-sized unions and zero-copy bytes.
  23. 2.23Compile-Time EvaluationConstants, const functions, comptime blocks and conditional compilation.
  24. 2.24Derivation and Source GeneratorsConformances the compiler writes for you, and generators that write code as a package builds.
  25. 2.25Modules and Access ControlModules and imports, the four visibility levels, and who may subclass and override.
  26. 2.26Unsafe Code and C Interopunsafe blocks and functions, raw memory, and calling C and being called from it.
  27. 2.27Documentation and TestingDoc comments with runnable examples, tests, benchmarks and fuzz targets.

Language Reference

Every part of the language stated completely: the lexical rules, types, expressions, statements, declarations, attributes, patterns and the grammar.

  1. 3.1Lexical StructureSource text, identifiers, the newline rule, keywords, literals, operators and directives.
  2. 3.2TypesEvery built-in type and every form of type syntax, and how types relate.
  3. 3.3ExpressionsEvery kind of expression, operator precedence, literals and how the compiler reads braces.
  4. 3.4StatementsEvery statement, its forms, and how control leaves a scope.
  5. 3.5DeclarationsEvery declaration and every modifier that may be written on one.
  6. 3.6AttributesEvery attribute the language knows, where it applies and what it does.
  7. 3.7PatternsEvery pattern form, where patterns may be written, and how they bind.
  8. 3.8Summary of the GrammarThe language's formal grammar, in EBNF.
Sable

A systems language with value semantics, automatic reference counting, move-checked resources and compile-time checks on how memory is used, compiled ahead of time to native code through LLVM.

Sable is pre-1.0: the language, the standard library and the toolchain work end to end, but expect changes between versions.