anchor.diff:  
   -export([encode/1,
            decode/1]).
  +
   
   %%============================================================================
   %% Constants
  
positive.code: -define(INITIAL_N, 128).
  -define(DELIMITER, $-).
  
  %%============================================================================
  %% Encoding algorithm state
  %%============================================================================
  
negative.code:   N + 22.
  
  
  decode(Input) ->
    {Output, Input2} = case string:rstr(Input, [?DELIMITER]) of
               0 -> {"", Input};
               Pos ->
                 {lists:sublist(Input, Pos - 1), lists:sublist(Input, Pos + 1, length(Input) )}
             end,
    decode(Input2, Output, ?INITIAL_N, ?INITIAL_BIAS, 0).
  
  
  decode([], Output, _, _, _) -> Output;
  decode(Input, Output, N, Bias, I) ->
    decode(Input, Output,  N, Bias, I, I, 1, ?BASE).
  
  decode([C|Rest], Output, N, Bias, I0, OldI, Weight, K) ->
    Digit = digit(C),
    I1 = case Digit > ((?MAX - I0 ) div Weight) of
           false -> I0 + (Digit * Weight);
           true -> exit(overflow)
         end,
  
    T = if
          K =< Bias -> ?TMIN;
          K >= (Bias + ?TMAX) -> ?TMAX;
          true -> K - Bias
        end,
    case Digit < T of
      true ->
        Len = length(Output),
        Bias2 = adapt(I1 - OldI, Len + 1, (OldI == 0)),
        {N2, I2}= case (I1 div (Len +1)) > (?MAX - N) of
                    false ->
                      {N + I1 div (Len + 1), I1 rem (Len + 1)};
                    true ->
                      exit(overflow)
                  end,
  
        {Head, Tail} = lists:split(I2, Output),
        Output2 = Head ++ [N2] ++ Tail,
        decode(Rest, Output2, N2, Bias2, I2+1);
      false ->
        case Weight > (?MAX  div (?BASE - T)) of
          false ->
            decode(Rest, Output, N, Bias, I1, OldI, Weight * (?BASE - T), K + ?BASE);
          true ->
            exit(overflow)
        end
    end.
  
  
  digit(C) when C >= $0, C =< $9 -> C - $0 + 26;
  digit(C) when C >= $A, C =< $Z -> C - $A;
  digit(C) when C >= $a, C =< $z -> C - $a.
  
  
  adapt(Delta, NumPoints, FirstTime) ->
    Delta2 = case FirstTime of
               true ->
                 Delta div ?DAMP;
               false ->
                 Delta div 2
             end,
    adapt(Delta2 + (Delta2 div NumPoints), 0).
  
  adapt(Delta, K) ->
    case Delta > (((?BASE - ?TMIN) * ?TMAX) div 2) of
      true ->
        adapt(Delta div (?BASE - ?TMIN), K + ?BASE);
      false ->
        K + (((?BASE - ?TMIN + 1) * Delta) div (Delta + ?SKEW))
    end.