From 6b2b1275c0d8fe4513db92cb3202ff37c118d927 Mon Sep 17 00:00:00 2001 From: David Vazquez Date: Thu, 27 Dec 2012 02:24:02 +0000 Subject: [PATCH] Print negative numbers --- lispstrack.lisp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) 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 -- 1.7.10.4