diff options
-rw-r--r-- | plus-inc.lisp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/plus-inc.lisp b/plus-inc.lisp index 3d85b11..cabc2d3 100644 --- a/plus-inc.lisp +++ b/plus-inc.lisp @@ -12,6 +12,12 @@ (defun may-reverse (number) "If units is placed on the end, reverse; else keep it." (if *number-units-at-beginning* + number + (reverse number))) + +(defun may-reverse-and-cut (number) + "If units is placed on the end, reverse; else keep it. Also cuts unecessary digits." + (if *number-units-at-beginning* (reverse (cut-digits (reverse number))) (reverse (cut-digits number)))) @@ -82,12 +88,12 @@ (defun plus (numerals a b) "Given a list of a numeral system and 2 lists of symbols, it returns the list of it's sum." - (may-reverse (plus-args-list numerals (may-reverse a) (may-reverse b)))) + (may-reverse (plus-args-list numerals (may-reverse-and-cut a) (may-reverse-and-cut b)))) (defun plus-decimal (&rest args) "Given decimal numbers, it returns the symbol it's sum." - (nth-value 0 (implode (may-reverse (reduce (lambda (a b) (plus-args-list '(|0| |1| |2| |3| |4| |5| |6| |7| |8| |9|) a b)) (mapcar #'may-reverse (mapcar #'explode args))))))) + (nth-value 0 (implode (may-reverse (reduce (lambda (a b) (plus-args-list '(|0| |1| |2| |3| |4| |5| |6| |7| |8| |9|) a b)) (mapcar #'may-reverse-and-cut (mapcar #'explode args))))))) (defun plus-earth (&rest args) "Give earthal numbers, it returns it's sum." - (symbol-to-number (nth-value 0 (implode (may-reverse (reduce (lambda (a b) (plus-args-list '(|1| |2| |3| |4| |5|) a b)) (mapcar #'may-reverse (mapcar #'explode args)))))))) + (symbol-to-number (nth-value 0 (implode (may-reverse (reduce (lambda (a b) (plus-args-list '(|1| |2| |3| |4| |5|) a b)) (mapcar #'may-reverse-and-cut (mapcar #'explode args)))))))) |