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.
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.
- 2.1The BasicsConstants and variables, the built-in types, type inference, tuples, optionals and assertions.
- 2.2Basic OperatorsArithmetic, overflow and wrapping, comparison, logic, ranges, and how operators bind.
- 2.3Strings and CharactersString literals, interpolation and format specs, Unicode, indices and substrings.
- 2.4Arrays and CollectionsThe array family, slices, ranges as places, dictionaries, and the library collections.
- 2.5Control Flowif and guard, loops, labels, defer and using, and switch.
- 2.6FunctionsLabels, defaults, variadics, inout and out parameters, overloading, generators and function types.
- 2.7ClosuresClosure syntax, trailing closures, captures and capture lists, escaping and autoclosures.
- 2.8Structures and ClassesValues and objects: record literals, memberwise initialisers, identity and inheritance.
- 2.9PropertiesStored and computed properties, observers, field-backed accessors, lazy and static properties.
- 2.10Methods, Subscripts and OperatorsInstance and static methods, mutating methods, subscripts, and overloading operators.
- 2.11Initialization and DeinitializationInitialisers, delegation, required and convenience initialisers, failing safely, and deinit.
- 2.12Enums and UnionsNamed integers and flag sets, tagged unions with payloads, and structural unions.
- 2.13Pattern Matchingmatch as a statement and an expression, every pattern form, guards and exhaustiveness.
- 2.14Optionalsnone, optional binding, chaining, defaults, force-unwrapping and narrowing.
- 2.15Error HandlingTyped throws, try and its forms, do-catch, rethrows, throwing iteration and panics.
- 2.16ProtocolsRequirements, associated types, default implementations, some and any, and composition.
- 2.17GenericsGeneric functions and types, constraints and where clauses, specialisation and variance.
- 2.18ExtensionsAdding members and conformances, constrained extensions, and extending every array.
- 2.19Casting, Metatypes and ReflectionCasts and type tests, key paths, types as values, opening existentials, and reflection.
- 2.20Concurrencyasync and await, structured tasks, cancellation, actors, Sendable and threads.
- 2.21Memory and OwnershipThe three tiers, reference counting, move-only types, exclusivity, references and regions.
- 2.22Inline LayoutContiguous pointer-free values, relative references, variant-sized unions and zero-copy bytes.
- 2.23Compile-Time EvaluationConstants, const functions, comptime blocks and conditional compilation.
- 2.24Derivation and Source GeneratorsConformances the compiler writes for you, and generators that write code as a package builds.
- 2.25Modules and Access ControlModules and imports, the four visibility levels, and who may subclass and override.
- 2.26Unsafe Code and C Interopunsafe blocks and functions, raw memory, and calling C and being called from it.
- 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.
- 3.1Lexical StructureSource text, identifiers, the newline rule, keywords, literals, operators and directives.
- 3.2TypesEvery built-in type and every form of type syntax, and how types relate.
- 3.3ExpressionsEvery kind of expression, operator precedence, literals and how the compiler reads braces.
- 3.4StatementsEvery statement, its forms, and how control leaves a scope.
- 3.5DeclarationsEvery declaration and every modifier that may be written on one.
- 3.6AttributesEvery attribute the language knows, where it applies and what it does.
- 3.7PatternsEvery pattern form, where patterns may be written, and how they bind.
- 3.8Summary of the GrammarThe language's formal grammar, in EBNF.