anchor.diff:  to_records(Defs) ->
     lists:flatten(lists:map(fun records/1, Defs)).
   
  -gname(Name) ->
  -  list_to_atom("kpro_" ++ string:strip(atom_to_list(Name), both, $')).
  +gname(Name) when is_atom(Name) ->
  +  gname(atom_to_list(Name));
  +gname(NameStr) when is_list(NameStr) ->
  +  list_to_atom("kpro_" ++ string:strip(NameStr, both, $')).
   
   records(Def) -> records(Def, Def).
   
  
positive.code:   [gen_record(Rec), gen_records(Rest)].
  
  gen_record({Name, Fields}) ->
    ["-record(", atom_to_list(Name), ",\n",
     "        { ",
                infix(gen_record_fields(Fields), "        , "),
     "        }).\n\n"
    ].
  
  %% change the first char to lower case
  lower_case_leading(Name) ->
    [H | T] = atom_to_list(Name),
    list_to_atom([H + ($a - $A) | T]).
  
  gen_record_fields([]) ->
    [];
  gen_record_fields([{Name, Type} | Fields]) ->
    FieldName = atom_to_list(Name),
    [ [ FieldName, " :: "
      , case Type of
          {one_of, Refs} -> gen_union_type(Refs, length(FieldName)+12);
          _              -> gen_field_type(list_to_atom(FieldName), Type)
        end
      , "\n"
      ]
    | gen_record_fields(Fields)
    ].
  
  gen_union_type(Refs, Width) ->
    Sep = "\n" ++ lists:duplicate(Width, $\s) ++ "| ",
    infix(lists:map(fun(Name) ->
                      atom_to_list(Name) ++ "()"
                    end, Refs), Sep).
  
  %% generate special pre-defined types.
  gen_field_type(errorCode, _)     -> "error_code()";
  
negative.code:             end, Fields).
  
  field_name(Name) when is_atom(Name) ->
    lowercase_leading(Name);
  field_name({array, Name}) ->
    %% for array fields, append a _L suffix to the name
    list_to_atom(atom_to_list(field_name(Name)) ++ "_L").
  