;lisp passo a passo digite: (trace negativo neg) ;================================================================ ;verifica se um numero eh negativo SxS -> {t,nil} (Defun ehnegativo(x) (Cond ((eq x 0)'t) ('t(ehneg x x)))) (Defun ehneg(a b) (Cond ((eq a 0)'t) ((eq b 0)'nil) ('t(ehneg (1+ a) (1- b) )))) ;================================================================ ;soma dois numeros A+B -> {A} ;depende de ehnagativo (Defun soma(a b) (Cond ((eq b 0) a) ((eq a 0) b) ('t(mais a b)))) (Defun mais(a b) (Cond ((eq b 0) a) ((ehnegativo b) (mais (1- a) (1+ b))) ('t (mais (1+ a) (1- b))))) ;================================================================ ;subtrai dois numeros A-B -> {A} ;depende de ehnegativo (Defun subtrai(a b) (Cond ((eq b 0) a) ((eq a 0) b) ('t (sub a b)) ) ) (Defun sub(a b) (Cond ((eq b 0) a) ((ehnegativo a) ((ehnegativo b) (sub (1+ a) (1+ b)) ((ehnegativo a) (sub (1+ a) (1- b))) ((ehnegativo b) (sub (1- a) (1+ b))) ('t(sub (1- a) (1- b)))))))