Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Statements

This chapter specifies the statement syntax of Dada.

Block definition

A block Block is a sequence of zero or more statements enclosed in curly braces:


Block ::= { Statement* }

A block evaluates to the value of its last expression, if the last statement is an expression statement.

Statement definition

A statement Statement is one of the following:


Statement ::= LetStatement
              | ExprStatement

LetStatement definition

A let statement LetStatement introduces a new variable binding:


LetStatement ::= let mut? Identifier (: Type)? (= Expr)?

A let statement may include a type annotation: let name: Type = value.

A let statement may use mut to declare a mutable binding: let mut name = value.

The initializer (= value) is optional. A variable may be declared without an initial value.

ExprStatement definition

An expression statement ExprStatement is an expression followed by a newline or end of block:


ExprStatement ::= Expr