From: David Vazquez Date: Thu, 27 Dec 2012 02:24:02 +0000 (+0000) Subject: Print negative numbers X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=6b2b1275c0d8fe4513db92cb3202ff37c118d927;p=jscl.git Print negative numbers --- diff --git a/lispstrack.lisp b/lispstrack.lisp index 288360b..5a23bdb 100644 --- a/lispstrack.lisp +++ b/lispstrack.lisp @@ -407,15 +407,19 @@ (concat (car list) separator (join-trailing (cdr list) separator)))) (defun integer-to-string (x) - (if (zerop x) - "0" - (let ((digits nil)) - (while (not (zerop x)) - (push (mod x 10) digits) - (setq x (truncate x 10))) - (join (mapcar (lambda (d) (string (char "0123456789" d))) - digits) - "")))) + (cond + ((zerop x) + "0") + ((minusp x) + (concat "-" (integer-to-string (- 0 x)))) + (t + (let ((digits nil)) + (while (not (zerop x)) + (push (mod x 10) digits) + (setq x (truncate x 10))) + (join (mapcar (lambda (d) (string (char "0123456789" d))) + digits) + ""))))) (defun print-to-string (form) (cond