lotus



previous page: L21) What characters are allowed in BETA identifiers?
  
page up: BETA Programming Language FAQ
  
next page: L23) What is the BETA lexem syntax?

L22) What is the exact semantics of leave P and restart P, when P is the name of a pattern?




Description

This article is from the FAQ, by with numerous contributions by others.

L22) What is the exact semantics of leave P and restart P, when P is the name of a pattern?

Leave and restart are the very basic local control mechanisms in BETA. Leave
and restart are specified by:

     restart id
     and
     leave id

where id is the name of either a label or an enclosing pattern. When id is
an enclosing pattern, id is defined to refer to the do-part of id (hence not
to the do-part of any superpattern of id).

Consider the pattern:

   P: A(# ...
       do (* L1 *)
          ...;
          leave/restart P;
          ...;
          (* L2 *)
       #)

restart P implies that execution continues at (* L1 *):

This means that restart P has the effect of entering the do-part
of P as after an inner in A.

leave P implies that execution continues at (* L2 *):

This means that leave P has the effect that execution continues in
the do-part of A after the inner that called the main-do-part of
P.

Example:

   (# A: (#
         do (for 4 repeat '['->put; INNER; ']'->put for)
         #);
      P: A (# k: @integer
           do k+1->k->putInt;
              (if k=2 then '-'->put; leave P if);
              (if k=3 then '*'->put; restart P if);
              '+'->put
           #);
   do P
   #)

will give the following output:

   [1+][2-][3*4+][5+]


 

Continue to:















TOP
previous page: L21) What characters are allowed in BETA identifiers?
  
page up: BETA Programming Language FAQ
  
next page: L23) What is the BETA lexem syntax?