Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Tour

    Language overview

    See how Topaz connects everyday programming, failure handling, concurrent work, and typesetting with explicit inputs.

    A language with typesetting built in

    Link

    Topaz is a general purpose language with typesetting built in. This nonnormative tour connects its main ideas through a complete program. The linked reference chapters define the rules.

    Bindings

    Link

    Bindings name values and introduce names into lexical scopes. Use let for immutable bindings, let mut for reassignment, and const for constant definitions.

    Types

    Link

    Types describe values and guide inference from annotations and surrounding expressions. Records, enums and newtypes give data a named shape, alternatives, or a distinct identity.

    Functions and abstraction

    Link

    Functions and generics define reusable calculations with parameter and result types. Functions are values, and lambdas provide short function expressions. Protocols and implementations name capabilities that generic code can require.

    Execution and control flow

    Link

    Expressions and operators compute values, while blocks and control flow sequence work and repeat effects. Pattern matching selects code by the shape of a value. Collections and comprehensions collect values from iteration.

    Determinism

    Link

    Language determinism concerns the order of evaluation and the values a program computes from its inputs. Typesetting determinism concerns the layout that program produces. For the same program and text, the same font data, measurements, Unicode version, policies, grid, and product release produce the same typesetting result. Font data and measurements are program inputs.

    Failure handling

    Link

    Failure and propagation separates expected errors in Result from runtime faults. Ok(value) carries success, Err(error) carries failure, and ? forwards an error from the enclosing function.

    Concurrency

    Link

    Concurrency runs named arms as a group and collects their values in a record. A Duration deadline gives the group a timeout and an else path.

    Modules

    Link

    Modules split a program into files and expose selected declarations through export and import. Imported declarations retain their defining identity, whether selected by name or reached through a module namespace.

    Libraries

    Link

    The library provides bytes, data formats, files, and standard input and output. Typesetting supplies measured lengths, text break classification, and paragraph plans. Lispex evaluates packaged rules with explicit inputs and limits.

    A complete program

    Link

    Save the program as language-overview.tpz. It prints each valid job and reports an error for a job with no copies.

    Print jobs and handle an error

    Link
    language-overview.tpzPrint jobs and handle an errorOpen in Playground
    1. import std.io
    2. record Job { text: string, copies: int }
    3. function checkedCopies(job: Job) -> Result<int, string> {
    4. if (job.copies > 0) {
    5. Ok(job.copies)
    6. } else {
    7. Err("copies must be positive")
    8. }
    9. }
    10. function printJob(job: Job) -> Result<int, string> {
    11. let copies: int = checkedCopies(job)?
    12. for copy in (0 ..< copies) {
    13. io.writeLine(job.text)
    14. }
    15. Ok(copies)
    16. }
    17. let jobs: Array<Job> = [
    18. Job { text: "Topaz", copies: 2 },
    19. Job { text: "Draft", copies: 0 },
    20. ]
    21. for job in (jobs) {
    22. match (printJob(job)) {
    23. case Ok(copies) => io.writeLine("printed {copies} copies")
    24. case Err(message) => io.writeLine(message)
    25. }
    26. }
    Expected outputexit 0
    Topaz
    Topaz
    printed 2 copies
    copies must be positive
    
    $ topaz run language-overview.tpz --compiler self · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. Topaz
    2. Topaz
    3. printed 2 copies
    4. copies must be positive
    Source evidence

    The first job reaches the loop and prints two lines. The second job returns an error through ?, so the final match prints its message.

    Menu

    Download