anchor.diff:      to_binding(?l2b(V));
   to_binding(V) ->
       {bind, V}.
  -
  -to_json(V) ->
  -    iolist_to_binary(?JSON_ENCODE(V)).
  
positive.code: make_query_list([], _Bindings, Acc) ->
      Acc;
  make_query_list([{Key, {Value}}|Rest], Bindings, Acc) ->
      Value1 = to_json({Value}),
      make_query_list(Rest, Bindings, [{to_binding(Key), Value1}|Acc]);
  make_query_list([{Key, Value}|Rest], Bindings, Acc) when is_binary(Value) ->
      Value1 = replace_var(Key, Value, Bindings),
      make_query_list(Rest, Bindings, [{to_binding(Key), Value1}|Acc]);
  make_query_list([{Key, Value}|Rest], Bindings, Acc) when is_list(Value) ->
      Value1 = replace_var(Key, Value, Bindings),
      make_query_list(Rest, Bindings, [{to_binding(Key), Value1}|Acc]);
  make_query_list([{Key, Value}|Rest], Bindings, Acc) ->
      make_query_list(Rest, Bindings, [{to_binding(Key), Value}|Acc]).
  
  replace_var(Key, Value, Bindings) ->
      case Value of
          <<":", Var/binary>> ->
              get_var(Var, Bindings, Value);
          <<"*">> ->
              get_var(Value, Bindings, Value);
          _ when is_list(Value) ->
              Value1 = lists:foldr(fun(V, Acc) ->
                  V1 = case V of
                      <<":", VName/binary>> ->
                          case get_var(VName, Bindings, V) of
                              V2 when is_list(V2) ->
                                  iolist_to_binary(V2);
                              V2 -> V2
                          end;
                      <<"*">> ->
                          get_var(V, Bindings, V);
                      _ ->
                          V
                  end,
                  [V1|Acc]
              end, [], Value),
              to_json(Value1);
          _ when is_binary(Value) ->
              Value;
          _ ->
              case Key of
                  <<"key">> -> to_json(Value);
                  <<"startkey">> -> to_json(Value);
                  <<"start_key">> -> to_json(Value);
                  <<"endkey">> -> to_json(Value);
                  <<"end_key">> -> to_json(Value);
                  _ ->
                      lists:flatten(?JSON_ENCODE(Value))
              end
      end.
  
  
  get_var(VarName, Props, Default) ->
      VarName1 = to_binding(VarName),
      couch_util:get_value(VarName1, Props, Default).
  
  %% doc: build new patch from bindings. bindings are query args
  %% (+ dynamic query rewritten if needed) and bindings found in
  
negative.code:     end,
      path_to_list(R, [P1|Acc], DotDotCount).
  
  maybe_encode_bindings([]) ->
      [];
  maybe_encode_bindings(Props) -> 
      lists:foldl(fun 
              ({{bind, <<"*">>}, V}, Acc) ->
                  Acc;
              ({{bind, K}, V}, Acc) ->
                  V1 = iolist_to_binary(maybe_json(K, V)),
                  [{K, V1}|Acc]
          end, [], Props).
                  
  decode_query_value({K,V}) ->
      case lists:member(K, ["key", "startkey", "start_key",
                  "endkey", "end_key", "keys"]) of
          true ->
              {to_binding(K), ?JSON_DECODE(V)};
          false ->
              {to_binding(K), ?l2b(V)}
      end.
  
  to_binding({bind, V}) ->
      {bind, V};
  