2 Language Concepts

This section documents the language forms in Pyret, as well as a number of Pyret-specific libraries and concepts, like Testing and Equality.

    2.1 Language Constructs

      2.1.1 Primitives and Literals

        2.1.1.1 Names

        2.1.1.2 String Literals

        2.1.1.3 Number Literals

        2.1.1.4 Boolean Literals

      2.1.2 Comments

      2.1.3 Programs

      2.1.4 Import Statements

      2.1.5 Provide Statements

      2.1.6 Bindings

        2.1.6.1 Name bindings

        2.1.6.2 Annotated bindings

        2.1.6.3 Shadowing

        2.1.6.4 Tuple bindings

      2.1.7 Blocks

        2.1.7.1 Block Shorthand

      2.1.8 Declarations

        2.1.8.1 Let Declarations

        2.1.8.2 Recursive Let Declarations

        2.1.8.3 Function Declaration Expressions

          2.1.8.3.1 Scope

          2.1.8.3.2 Where blocks

          2.1.8.3.3 Syntactic sugar

        2.1.8.4 Data Declarations

        2.1.8.5 Variable Declarations

        2.1.8.6 Type Declarations

        2.1.8.7 Newtype Declarations

      2.1.9 Contracts

      2.1.10 Statements

        2.1.10.1 When Statements

        2.1.10.2 Assignment Statements

        2.1.10.3 Binop Expression “Statements”

      2.1.11 Expressions

        2.1.11.1 Lambda Expressions

        2.1.11.2 Curly-Brace Lambda Shorthand

        2.1.11.3 Anonymous Method Expressions

        2.1.11.4 Application Expressions

        2.1.11.5 Curried Application Expressions

        2.1.11.6 Chaining Application

        2.1.11.7 Instantiation Expressions

        2.1.11.8 Binary Operators

        2.1.11.9 Tuple Expressions

        2.1.11.10 Tuple Access Expressions

        2.1.11.11 Object Expressions

        2.1.11.12 Dot Expressions

        2.1.11.13 Extend Expressions

        2.1.11.14 If Expressions

        2.1.11.15 Ask Expressions

        2.1.11.16 Cases Expressions

        2.1.11.17 For Expressions

        2.1.11.18 Template (...) Expressions

        2.1.11.19 Tables

          2.1.11.19.1 Sorting Table Rows

          2.1.11.19.2 Transforming Table Rows

          2.1.11.19.3 Extracting Table Columns

          2.1.11.19.4 Adding Table Columns

        2.1.11.20 Table Loading Expressions

        2.1.11.21 Reactor Expressions

        2.1.11.22 Mutable fields

        2.1.11.23 Construction expressions

        2.1.11.24 Expression forms of bindings

      2.1.12 Annotations

        2.1.12.1 Name Annotations

        2.1.12.2 Parametric Annotations

        2.1.12.3 Arrow Annotations

        2.1.12.4 Predicate Annotations

        2.1.12.5 Tuple Annotations

        2.1.12.6 Record Annotations

    2.2 Testing

      2.2.1 check: and where: blocks

        2.2.1.1 check: blocks

        2.2.1.2 where: blocks

      2.2.2 Testing Operators

        2.2.2.1 Binary Test Operators

        2.2.2.2 Unary Test Operators

        2.2.2.3 Exception Test Operators

      2.2.3 Reasons for tests: because clauses

        2.2.3.1 Using because with other testing operators

    2.3 equality

      2.3.1 Types of Equality

      2.3.2 Equal Now

        2.3.2.1 Equal Now and Primitives

        2.3.2.2 Equal Now and Structured Data

        2.3.2.3 Equal Now and References

      2.3.3 Identical

        2.3.3.1 Identical and Primitives

        2.3.3.2 Identical and Structural Equality

        2.3.3.3 Identical and Mutable Data

      2.3.4 Always Equal

        2.3.4.1 Always Equal and Mutable Data

      2.3.5 Properties of Equality Functions

      2.3.6 Bounded Equalities

      2.3.7 Undefined Equalities

        2.3.7.1 Roughnums and Equality

        2.3.7.2 Functions and Equality

      2.3.8 Total Equality Functions (Avoiding Incomparability Errors)

      2.3.9 Datatype-defined Equality

      2.3.10 Inequalities

    2.4 Combining Multiple Operators

      2.4.1 But why not use precedence?

    2.5 Modules

      2.5.1 Quick Start

      2.5.2 Finding Modules

      2.5.3 Detailed Control of Names

      2.5.4 import and Module Identifiers

      2.5.5 Providing Fewer (and More) Names

        2.5.5.1 Re-exporting values

      2.5.6 Providing more than just values

        2.5.6.1 Types

        2.5.6.2 Modules

        2.5.6.3 Data definitions

      2.5.7 Including Fewer (and More) Names

      2.5.8 Importing more than just values

      2.5.9 Converting between shorthand and expanded syntax

    2.6 Use

      2.6.1 Contexts

        2.6.1.1 Backwards and Forwards Compatibility

    2.7 Brands

    2.8 Type Checking

      2.8.1 Required Annotations

      2.8.2 Working with Data Types

      2.8.3 Record Types

    2.9 Spies

      2.9.1 Examples

      2.9.2 Minor Notes and Corner Cases

      2.9.3 Grammar

      2.9.4 Rationale