Realmente tenemos que cambiar poco en comparación con la macro NATIVE_INTEGER_BINARY. Un if antes de la división que lance una excepción si intentamos dividir por cero y otro if que impida dividir sin argumentos. Esto es así porque la división no tiene un elemento neutro.
#define NATIVE_INTEGER_BINARY_DIVISION(name, op) \
CELL& Native_##name(Script& script, CELL& args, CELL& envir) \
{ CELL* a=&script.Evaluate(args, envir); \
int r=0; \
if(a->type!=CONS_CTOR) throw L"Division arity must not be zero"; \
r=a->head->GetInteger(); \
for(a=a->tail; a->type==CONS_CTOR; a=a->tail) \
{ int d=a->head->GetInteger(); \
if(d==0) throw L"Division by zero"; \
r=r op d; \
} \
return script.CreateInteger(r); \
}Esto que hemos hecho hasta ahora es una macro. Con esta macro, generamos las funciones para la división y para el resto.NATIVE_INTEGER_BINARY_DIVISION(Div, /) NATIVE_INTEGER_BINARY_DIVISION(Mod, %)En el siguiente post, veremos los operadores relacionales. Estos operadores son distintos a los aritméticos ya que siempre devuelven un booleano. Por eso requieren un tratamiento especial.
