%PROG hand == []
[
  %VAR
  [
    handnum, i : INT 
    
  ]
  %PROS
  [
    askfor( %CHN/ ch ( *, con : NM ) : INT ) == 
    [
      %alg
      [
        LB= START => $OLB = NEXT ; 
        LB= l0 => $O handnum = handnum + 1 ^ $O i = i + 1 ^ $OLB = NEXT ; 
        LB= l10 => WRITELN ( "This is the " , i , "th ask for hand" ) ; 
        LB= l11 => WRITELN ( "This is the " , handnum , "th ask for hand after response" ) ; 
        LB= l12 => $O ch !handnum ^ $OLB = NEXT ; 
        LB= l13 ^ ( i < 5 ) => $OLB = l0 ; 
        LB= l14 => $OLB = STOP 
        
      ]
    ];
    //end of askfor
    //---------------------------------------
    response ( %CHN/ ch ( con : NM , *) : INT ) == 
    [
      %alg
      [
        LB= START => $OLB = NEXT ; 
        LB= l0 => $O ch ?handnum ^ $OLB = NEXT ; 
        LB= l10 => WRITELN ( "Response " , handnum ) ; 
        LB= l11 => $O handnum = handnum - 1 ^ $OLB = NEXT ; 
        LB= l12 ^ ( i < 5 ) => $OLB = l0 ; 
        LB= l13 => $OLB = STOP 
        
      ]
    ]
    //end of response
    
  ]
  //end of pros
  
  [
    %LOC
    [
      ask, res : NM 
    ]
    %STM
    [
      LB= START => $O handnum = 0 ^ $O i = 0 ^ $OLB = NEXT ; 
      LB= l10 => $O ask == askfor ^ $O res == response ^ $OLB = NEXT ; 
      LB= l11 => || 
      [
        ask{ 1 } ( %CHN/ ch ( *, res ) | ch ( *, con ) ) ; 
        res{ 1 } ( %CHN/ ch ( ask , *) | ch ( con , *) ) 
      ];
      
      LB= l12 => $OLB = RETURN 
    ]  
    ]
  ]
.
