Chapter 3Basic expression types

Note

This chapter will be extended by a future fascicle.

1Variables

variable

SyntaxAn expression consisting of an identifier is a variable reference if it is not a macro use .

SemanticsWhen a variable reference is evaluated, the value stored in the location to which the variable named by the identifier is bound is accessed and returned.

It is a violation of type &undefined to attempt to access the value of an unbound variable. Implementations should detect and report this violation within the bodies of top-level, and within the bodies of any libraries imported from top-level programs (including in any libraries which those libraries in turn import), before evaluation of the program begins. Implementations should also detect and report this violation in the bodies of libraries which are imported in interactive mode before the bindings of that library are made available.

  |(define x 28)
  |x  ⇒  28

1.2Procedure applications

(operator operand1 …)

SyntaxA procedure call consists of expressions for the procedure to be called and the arguments to be passed to it, with enclosing parentheses. A form in an expression context is a procedure call if the operator is not an identifier bound as a syntax keyword.

SemanticsWhen a procedure call is evaluated, the operator and operand expressions are evaluated in an unspecified order, and the procedure resulting from evaluating the operator is passed the arguments resulting from evaluating the operands.

  |(+ 3 4) ⇒ 7
  |((if #f + *) 3 4) ⇒ 12

The result of evaluating the operator and each of the operand expressions must be a single value. If zero values or more than one value is returned from any of these evaluations, implementations should raise an exception with condition type &assertion; any other behaviour in this situation is implementation-specified.

If the value of operator is not a procedure, an exception with condition type &assertion is raised. If operator does not accept as many arguments as there are operands, it is a domain error.

Procedure calls can return any number of values (see values in section Section 2, “Procedures”).

Note

In contrast to other dialects of Lisp, the order of evaluation is unspecified, and the operator expression and the operand expressions are always evaluated with the same evaluation rules.

Although the order of evaluation is otherwise unspecified, the effect of any concurrent evaluation of the operator and operand expressions is constrained to be consistent with some sequential order of evaluation. The order of evaluation may be chosen differently for each procedure call.

Note

In many dialects of Lisp, the form () is a legitimate expression. In Scheme, expressions written as list/pair forms must have at least one subexpression, so () is not a syntactically valid expression. It is unspecified whether it is a syntax violation or evaluates to the empty list or some other value.