Revised7 Report on the Algorithmic Language Scheme

Page 10

Revised7 Scheme

10

(let*-values (hformalsi*) htail bodyi) (let-syntax (hsyntax speci*) htail bodyi) (letrec-syntax (hsyntax speci*) htail bodyi)

calls. Derived expression types are not semantically primitive, but can instead be defined as macros. Suitable definitions of some of the derived expressions are given in section 7.3.

(begin htail sequencei)

4.1. Primitive expression types (do (hiteration speci*) (htesti htail sequencei) hexpressioni*) where hcond clausei −→ (htesti htail sequencei) hcase clausei −→ ((hdatumi*) htail sequencei) htail bodyi −→ hdefinitioni* htail sequencei htail sequencei −→ hexpressioni* htail expressioni

• If a cond expression is in a tail context, and has a clause of the form (hexpression1 i => hexpression2 i) then the (implied) call to the procedure that results from the evaluation of hexpression2 i is in a tail context. hexpression2 i itself is not in a tail context. Certain built-in procedures are also required to perform tail calls. The first argument passed to apply and to call-with-current-continuation, and the second argument passed to call-with-values, must be called via a tail call. Similarly, eval must evaluate its first argument as if it were in tail position within the eval procedure. In the following example the only tail call is the call to f. None of the calls to g or h are tail calls. The reference to x is in a tail context, but it is not a call and thus is not a tail call. (lambda () (if (g) (let ((x (h))) x) (and (g) (f)))) Note: Implementations are allowed, but not required, to recognize that some non-tail calls, such as the call to h above, can be evaluated as though they were tail calls. In the example above, the let expression could be compiled as a tail call to h. (The possibility of h returning an unexpected number of values can be ignored, because in that case the effect of the let is explicitly unspecified and implementation-dependent.)

4.

Expressions

Expression types are categorized as primitive or derived. Primitive expression types include variables and procedure

4.1.1. Variable references hvariablei

syntax

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

4.1.2. Literal expressions (quote hdatumi) ’hdatumi hconstanti

syntax syntax syntax

(quote hdatumi) evaluates to hdatumi. hDatumi 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) (quote #(a b c)) (quote (+ 1 2))

=⇒ =⇒ =⇒

a #(a b c) (+ 1 2)

(quote hdatumi) may be abbreviated as ’hdatumi. The two notations are equivalent in all respects. ’a ’#(a b c) ’() ’(+ 1 2) ’(quote a) ’’a

=⇒ =⇒ =⇒ =⇒ =⇒ =⇒

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

Numerical constants, string constants, character constants, and boolean constants evaluate “to themselves”; they need not be quoted. ’"abc" "abc" ’145932 145932 ’#t #t

=⇒ =⇒ =⇒ =⇒ =⇒ =⇒

"abc" "abc" 145932 145932 #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!.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.