anchor.diff:     general_compare(Op,L1,L2);
   general_compare(Op,L1,{array,L2}) -> 
      general_compare(Op,L1,L2);
  -general_compare(Op,#xqAtomicValue{} = List1,#xqAtomicValue{} = List2) ->
  -   value_compare(Op,List1,List2);
  -general_compare(Op,#xqRange{} = List1,#xqAtomicValue{} = V2) ->
  -   Bool = range_val_comp_any(Op, List1, V2),
  +general_compare(Op, A1, A2) when ?is_atomic(A1), ?is_atomic(A2) ->
  +   value_compare(Op, A1, A2);
  +general_compare(Op, #xqRange{} = List1, A2) when ?is_atomic(A2) ->
  +   Bool = range_val_comp_any(Op, List1, A2),
      ?bool(Bool);
  -general_compare(Op,#xqAtomicValue{} = V1,#xqRange{} = List2) ->
  -   Bool = range_val_comp_any(Op, V1, List2),
  +general_compare(Op, A1, #xqRange{} = List2) when ?is_atomic(A1) ->
  +   Bool = range_val_comp_any(Op, A1, List2),
      ?bool(Bool);
   general_compare(Op,#xqRange{} = List1,#xqRange{} = List2) ->
      Bool = range_range_comp_any(Op, List1, List2),
      ?bool(Bool);
      
  -general_compare(Op,#xqAtomicValue{} = V1,List2) when is_list(List2) ->
  -   Bool = general_compare_any_2(List2, Op, V1),
  +general_compare(Op, A1, List2) when ?is_atomic(A1), is_list(List2) ->
  +   Bool = general_compare_any_2(List2, Op, A1),
      ?bool(Bool);
  -general_compare(Op, V1, List2) when is_list(List2), is_boolean(V1) ->
  -   Bool = general_compare_any_2(List2, Op, V1),
  +general_compare(Op, List1, A2) when is_list(List1), ?is_atomic(A2) ->
  +   Bool = general_compare_any_1(List1, Op, A2),
      ?bool(Bool);
  -general_compare(Op,List1,#xqAtomicValue{} = V2) when is_list(List1) ->
  -   Bool = general_compare_any_1(List1, Op, V2),
  -   ?bool(Bool);
  -general_compare(Op, List1, V2) when is_list(List1), is_boolean(V2) ->
  -   Bool = general_compare_any_1(List1, Op, V2),
  -   ?bool(Bool);
  -general_compare(Op, V1, V2) when is_boolean(V1), is_boolean(V2) ->
  -   value_compare(Op, V1, V2);
   
   general_compare(Op, V1, #{nk := _} = V2) ->
      general_compare(Op, V1, xqerl_types:atomize(V2));
  
positive.code:    atomize_list([Seq]);
  atomize_list([]) -> [].
  
  % returns: numeric
  numeric_add(A, B) -> 
     TV = fun(I) when is_integer(I) ->
                {'xs:integer', I};
             (I) when is_float(I) ->
                {'xs:double', I};
             (#xqAtomicValue{type = TypeA0, value = neg_zero}) when ?xs_numeric(TypeA0) ->
                {TypeA0, 0.0};
             (#xqAtomicValue{type = TypeA0, value = ValA0}) when ?xs_numeric(TypeA0) ->
                {TypeA0, ValA0};
             (neg_zero) ->
                {'xs:double', 0.0};
             (At) when At == nan;
                       At == neg_infinity;
                       At == infinity ->
                {'xs:double', At};
             (_) ->
                ?err('XPTY0004')
          end,
     {TypeA, ValA} = TV(A),
     {TypeB, ValB} = TV(B),
     TypeC = if TypeA =:= TypeB -> TypeA;
                true ->
                   get_numeric_type(TypeA, TypeB)
  
negative.code:                               Orig)
     end.
  
  -define(is_atomic(A), is_record(A, xqAtomicValue) orelse is_number(A) orelse is_boolean(A) orelse is_binary(A)).
  
  % returns xs:boolean
  general_compare(_Op,[],_) -> false;
  general_compare(_Op,_,[]) -> false;
  