diff options
author | Daniel Santos <dacs.git@brilhante.top> | 2023-01-10 17:31:05 +0000 |
---|---|---|
committer | Daniel Santos <dacs.git@brilhante.top> | 2023-01-10 17:45:16 +0000 |
commit | 91fcf477721c1571f20b25de633e5cf8314bd81e (patch) | |
tree | 704c7c4288dbd1da526f2120bf8b00982ade3ac8 | |
parent | 8be733f5ae19d06c0972b30925f16f0ca2687d77 (diff) | |
download | cl-math-91fcf477721c1571f20b25de633e5cf8314bd81e.tar.gz |
add implode, explode and may-reverse
Add the functions implode, explode, may-reverse and the variable *number-units-beginning*
-rw-r--r-- | cl-math.lisp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/cl-math.lisp b/cl-math.lisp index a217df4..86c7a81 100644 --- a/cl-math.lisp +++ b/cl-math.lisp @@ -1,6 +1,8 @@ ;;; plus one function ;;; it is the (next-number) and the (next-number-reversed) +(defvar *number-units-beginning* nil) + (defun next-digit (numerals digit) "Given a list of a numeral system and a digit, it returns the next digit." (cond @@ -14,6 +16,20 @@ ((zerop number) nil) (t (cons (mod number 10) (split-number-reversed (truncate number 10)))))) +(defun may-reverse (number) + "If units is placed on the end, reverse; else keep it." + (if *number-units-beginning* + (reverse number) + number)) + +(defun explode (number) + "Given a number (which can have letters), it returns a list of the number" + (may-reverse (loop for letter across (write-to-string number) collect (intern (string letter))))) + +(defun implode (number) + "Given a list of a number (which can have letters), it returns the number" + (intern (apply #'concatenate 'string (mapcar #'symbol-name (may-reverse number))))) + (defun next-list-number (numerals number-list-reversed) "Given a list of a numeral system and a list of a number, it returns a list of the next number." (cond |