Page:AIM-353.djvu/8

From Wikisource
Jump to navigation Jump to search
This page has been validated.
Steele and Sussman March 10, 1976 6 LAMBDA: The Ultimate Imperative

begin
       S1;
       begin
              S2;
              begin
                     ...
                            begin
                                   Sn-1;
                                   Sn;
                            end;
                     ...
              end;
       end;
end

It is not immediately apparent that this sequencing can be expressed in a purely applicative language. We can, however, take advantage of the implicit sequencing of applicative order evaluation. Thus, for example, we may write a two-statement sequence as follows:

((LAMBDA (DUMMY) S2) S1)

where DUMMY is an identifier not used in S2. From this it is manifest that the value of S1 is ignored, and so is useful only for side effects. (Note that we did not claim that S1 is expressed in a purely applicative language, but only that the sequencing can be so expressed.) From now on we will use the form (BLOCK S1 S2) as an abbreviation for this expression, and (BLOCK S1 S2 ... Sn-1 Sn) as an abbreviation for

(BLOCK S1 (BLOCK S2 (BLOCK ... (BLOCK Sn-1 Sn)...)))

The GO TO Statement

A more general imperative structure is the compound statement with labels and GO TOs. Consider the following code fragment due to Jacopini, taken from Knuth: [Knuth 74]

begin
L1: if B1 then go to L2;
    SI;
    if B2 then go to L2;
    S2;
    go to L1;
L2: S3;
end

It is perhaps surprising that this piece of code can be syntactically transformed into a purely applicative style. For example, in SCHEME we could