-module(compmacro).
-export([f/2]).
-record(pair,{left,right}).
-define( tuple_to_pair_rec, 
         (fun({E1,E2}) -> #pair{left=E1,right=E2};
             (X) -> X end)).

f(A,B) -> 
    if (A==0) or (B==0) ->
            throw(zero_is_an_illegal_argument);
        true ->
            f_({abs(A),abs(B)}) end.

f_({A,0}) -> A;
f_(R) -> 
    f_(fun(#pair{left=X,right=Y})->{Y, X rem Y} end
         (?tuple_to_pair_rec(R))).

