sysl

The Tour

The language and its standard library, in the order they make sense to learn.

The tour teaches sysl in one pass, from print to a program that reads its input and reports what it found. It assumes you can already program in something, and that you have used a language with types before — it does not assume you have used a systems language.

Every program on these pages runs. They are not sketches: the test suite compiles each one and checks it against the output printed beneath it, so a page that has drifted from the compiler fails the build rather than misleading you. Paste any of them into a file and run it with sbt "syslJVM/run run <file>.sysl".

A sysl block with an output block under it is a whole program and that is what it prints. A sysl block with an error block under it is a program the compiler refuses, and that is what it says — the refusals are worth as much as the acceptances, so the tour shows them. A sysl block standing on its own is a fragment, quoted to make a point about shape rather than to be run.

The order is deliberate. The three memory modes come early — around a third of the way in, well before generics or traits — because they are what makes sysl a different language rather than a different syntax, and because everything after them reads better once you know which of the three a type is in.

Pages

  • Values and bindings — Three ways to name a value, a scalar family with no surprises in it, and why nothing widens on its own.
  • Control flow — Everything yields a value — including the loops, which is less strange than it sounds.
  • Functions — An expression after `=`, or an indented block. Defaults, names at the call, and closures.
  • Structs and methods — Data with a name, then behaviour beside it — and a receiver that says how the method takes the instance.
  • Memory — Three modes, chosen per declaration. No garbage collector, no borrow checker, and no allocation keyword.
  • Arrays and slices — One type for storage, one for a view of it — and every index checked.
  • Strings — An immutable, validated `[]u8` — the same three words, with a guarantee added and an operation taken away.
  • Enums and patterns — A named set of constants, or a closed set of shapes — and the one expression that takes either apart.
  • Error handling — Two channels — a failure you handle is a value, and a bug stops the program.
  • Traits and generics — One mechanism for polymorphism, two ways to spend it — a bound for static dispatch, a sigil for dynamic.
  • Modules and the library — A module is a directory, an import only shortens a name you could always write in full, and the standard library is one auto-imported module with ten submodules under it.
  • Contracts and constrained types — A type that carries a rule, a struct that keeps one, and a function that states what it requires.
  • A program that reads its input — The whole tour at once — a trait implemented, a cursor walked, and one line to swap the source.

Search

Esc
to navigate to open Esc to close