anchor.diff:    catch _:R -> {stop,{R,erlang:get_stacktrace()},LD}
     end.
   
  +ok(X) -> {ok,X}.
   noreply(LD) -> {noreply,LD}.
   reply({Reply,LD}) -> {reply,Reply,LD}.
   
  
positive.code: -export([print_state/0]).
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% boiler plate
  -behaviour(gen_server).
  -export([handle_call/3, handle_cast/2, handle_info/2, 
           init/1, terminate/2, code_change/3]).
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% boiler plate
  init(X) -> {ok,do_init(X)}.
  terminate(Reason,LD) -> do_terminate(Reason,LD).
  code_change(_,LD,_) -> {ok,LD}.
  handle_cast(In,LD) -> gen_safe(fun(Ld)->noreply(do_cast(In,Ld))end,LD).
  handle_info(print_state,LD) -> print_term(expand_recs(LD)),noreply(LD);
  handle_info(In,LD) -> gen_safe(fun(Ld)->noreply(do_info(In,Ld))end,LD).
  handle_call(stop,_From,LD) -> {stop,shutdown,stopped,LD};
  handle_call(print_state,_,LD) -> print_term(expand_recs(LD)),reply({ok,LD});
  handle_call(In,_,LD) -> gen_safe(fun(Ld)->reply(do_call(Ld,In))end,LD).
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% API
  
negative.code: 
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% the state
  -record(ld,{args,acceptor,socket,subscribers=[],cookie="I'm a Cookie"}).
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% this should be put in here by the compiler. or a parse_transform...
  %% needs a new clause for each record definition
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  ri(ld) ->record_info(fields,ld);
  ri(_) -> [].
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% constants
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  sock_opts() -> [binary, {reuseaddr,true}, {active,false}, {packet,4}].
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% user code
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  do_init(Args) -> 
    #ld{args=Args, acceptor=accept(producer,56669,sock_opts())}.
  
  do_terminate(_LD,_Reason) -> ok.
  
  do_code_change(LD,_Xtra) -> LD.
  
  do_call(LD,Msg) -> print_term(Msg),{ok,LD}.
  
  do_cast(LD,Msg) -> print_term(Msg),LD.
  
  do_info(LD,{new_socket,producer,Sock}) ->
    %% we got a socket from a producer.
    inet:setopts(Sock,[{active,once}]),
    LD#ld{socket=Sock};
  do_info(LD,{tcp,Sock,Bin}) when LD#ld.socket==Sock -> 
    gen_tcp:close(Sock),
    Msg = prf_crypto:decrypt(LD#ld.cookie,Bin),
    lists:foreach(fun(S)->S!Msg end, LD#ld.subscribers),
    LD#ld{socket=[]};
  do_info(LD,Msg) -> 
    print_term(Msg),
    LD.
  
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  