You are looking at historical revision 20938 of this page. It may differ significantly from its current revision.

This document describes Chicken's R5RS support, with a heavy emphasis on syntax and procedures. It is based directly on the Revised^5 Report on the Algorithmic Language Scheme.

Overview of Scheme

Lexical conventions

Basic concepts


Expression types are categorized as primitive or derived. Primitive expression types include variables and procedure calls. Derived expression types are not semantically primitive, but can instead be defined as macros. With the exception of quasiquote, whose macro definition is complex, the derived expressions are classified as library features. Suitable definitions are given in section 7.3.

Primitive expression types

Variable references

[syntax] <variable>

An expression consisting of a variable (section 3.1) is a variable reference. The value of the variable reference is the value stored in the location to which the variable is bound. It is an error to reference an unbound variable.

(define x 28)
x           ===>  28

Literal expressions

[syntax] (quote <datum>)
[syntax] '<datum>
[syntax] <constant>

(quote <datum>) evaluates to <datum>. <Datum> may be any external representation of a Scheme object (see section 3.3). This notation is used to include literal constants in Scheme code.

(quote a)                    ===>  a
(quote #(a b c))             ===>  #(a b c)
(quote (+ 1 2))              ===>  (+ 1 2)

(quote <datum>) may be abbreviated as '<datum>. The two notations are equivalent in all respects.

'a                           ===>  a
'#(a b c)                    ===>  #(a b c)
'()                          ===>  ()
'(+ 1 2)                     ===>  (+ 1 2)
'(quote a)                   ===>  (quote a)
''a                          ===>  (quote a)

Numerical constants, string constants, character constants, and boolean constants evaluate "to themselves"; they need not be quoted.

'"abc"             ===>  "abc"
"abc"              ===>  "abc"
'145932            ===>  145932
145932             ===>  145932
'#t                ===>  #t
#t                 ===>  #t

As noted in section 3.4, it is an error to alter a constant (i.e. the value of a literal expression) using a mutation procedure like set-car! or string-set!.

Procedure calls

[syntax] (<operator> <operand[1]> ...)

A procedure call is written by simply enclosing in parentheses expressions for the procedure to be called and the arguments to be passed to it. The operator and operand expressions are evaluated (in an unspecified order) and the resulting procedure is passed the resulting arguments.

(+ 3 4)                           ===>  7
((if #f + *) 3 4)                 ===>  12

A number of procedures are available as the values of variables in the initial environment; for example, the addition and multiplication procedures in the above examples are the values of the variables + and *. New procedures are created by evaluating lambda expressions (see section 4.1.4). Procedure calls may return any number of values (see values in section 6.4). With the exception of values the procedures available in the initial environment return one value or, for procedures such as apply, pass on the values returned by a call to one of their arguments.

Procedure calls are also called combinations.

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.

Note: 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 empty combination, (), is a legitimate expression. In Scheme, combinations must have at least one subexpression, so () is not a syntactically valid expression.


<macro>(lambda <formals> <b