Previous section: Expressions

Dylan reference manual -- Statement bodies

Statement bodies

Many kinds of expressions include implicit bodies, which may contain one or more other expressions, separated by semicolons. When an implicit body is evaluated, the expressions in the implicit body are evaluated in order (left to right). The value of the implicit body is the value of the last expression.

The simplest expression containing an implicit body is begin.

begin	[Special Form]
    body
end
=>  values
The body consists of any number of expressions separated by semicolons. begin executes the expressions in the body sequentially. The values of the last expression are returned. If there are no expressions in the body, #f is returned.
begin
  close(airlock.outer-door);	// this
  pressurize(airlock);	// is an
  open(airlock.inner-door);	// implicit body
end;
Programs only need to use begin explicitly in order to limit the scope of a lexical variable, or in situations where a single expression is expected, such as an argument to a function call. Many other expressions contain implicit bodies. For example, the body of a method definition is an implicit body, and the if statement has an implicit body in each sub-part.
if (moon-phase == #"full")
  wolf-form(werewolf);	// this is an
  howl-at-moon(werewolf);	// implicit body
else
  human-form(werewolf);
end if;
Some statements use the word end to mark the end of an implicit body. Other statements use other markers, such as the else that marks the end of the first implicit body in an if statement. The syntax description for each statement defines where implicit bodies may appear, and how the boundary is marked.

Semicolons

Multiple expressions, such as top-level expressions appearing in source files, are separated by a semicolon ";". Semicolons are also required to separate all but the last expression in implicit bodies. The semicolon after the last expression is optional.

Next section: Special function call syntax