anchor.diff:                  }).
   
   -record(state,{ id,
  -                state,
  -                word
  +                state
                 }).
    
   % API
  
positive.code: 
  write_then_read_test() ->
     Channel = create(666),
     ?assertEqual(ok,write(Channel,123)),
     ?assertEqual({ok,123},read (Channel)),
     ?assertEqual(closed,close(Channel)).
  
  read_then_write_test() ->
     Channel = create(666),
     M       = self(),
     spawn(fun() -> M ! { read, read (Channel)     } end),
     spawn(fun() -> M ! { write,write(Channel,123) } end),
     ?assertEqual({ok,{ok,123}},wait(undefined,undefined)).
   
  wait({write,W},{read,R}) ->
     {W,R};
  
negative.code: % INTERNAL
  
  loop(State) ->
     ID = State#state.id,
  
     receive
        { close,PID } ->
           PID ! { closed,{channel,ID} },
           closed;
  
        { write,Word,WRITER } ->
           case State#state.state of 
              idle ->
                 loop(State#state{state = {write_pending,{Word,WRITER}} 
                                 });
  
              {read_pending,READER} ->
                 READER ! { read,   {channel,ID},Word },
                 WRITER ! { written,{channel,ID}      },
                 loop(State#state{state = idle
                                 });
              _else ->
                 loop(State)
              end;
  
  
        {read,READER } ->
           case State#state.state of 
              idle ->
                 loop(State#state{state = {read_pending,READER} 
                                 });
  
              { write_pending,{Word,WRITER}} ->
                 WRITER ! { written,{channel,ID}      },
                 READER ! { read,   {channel,ID},Word },
                 loop(State#state{ state=idle });
  
              _else ->
                 loop(State)
              end;
  
  