Page:AIM-353.djvu/6



 (DEFINE FACT  (LAMBDA (M) (LABELS ((FACT1 (LAMBDA (M ANS) (IF (= M 0) ANS                                  (FACT1 (- M 1) (* M ANS))))))               (FACT1 N 1))))

From this we can infer a general way to express iterations in SCHEME in a manner isomorphic to the MacLISP. The expansion of the general  loop

 (DO ( . . .    (&lt;varn>  ))        )

is this:

 (LABELS ((DOLOOP         (LAMBDA (DUMMY  ... &lt;varn>) (IF                   (DOLOOP   ... )))))       (DOLOOP NIL  ... ))

The identifiers  and   are chosen so as not to conflict with any other identifiers in the program.

Note that, unlike most implementations of, there are no side effects in the steppings of the iteration variables. loops are usually modelled using assignment statements. For example:

 for x := a step b until c do ;

can be modelled as follows: [Naur 63]

 begin x := a; L: if (x-c)*sign(b) > 0 then go to Endloop; ; x := x+b; go to L; Endloop: end;

Later we will see how such assignment statements can in general be modelled without using side effects.