format supports ~%
authorRaimon Grau <raimonster@gmail.com>
Fri, 26 Apr 2013 00:31:13 +0000 (02:31 +0200)
committerRaimon Grau <raimonster@gmail.com>
Fri, 26 Apr 2013 00:31:13 +0000 (02:31 +0200)
src/print.lisp

index f4cd1bb..428b044 100644 (file)
   (write-line (prin1-to-string x))
   x)
 
-#+jscl
-(progn
-  (defun format (destination fmt &rest args)
-    (let ((len (length fmt))
-         (i 0)
-         (res "")
-         (arguments args))
-      (cl:%while (< i len)
-                (let ((c (char fmt i)))
-                  (if (char= c #\~)
-                      (let ((next (char fmt (incf i))))
-                        (if (char= next #\~)
-                            (progn (setq res (cl:concat res "~"))
-                                   (incf i))
-                            (progn
-                              (format-special next (car arguments))
-                              (setq arguments (cdr arguments)))))
-                      (progn
-                        (setq res (cl:concat res (cl:char-to-string c)))))
-                  (incf i)))
-      (if destination
-         (progn
-           (write-string res)
-           nil)
-         res)))
+(defun format (destination fmt &rest args)
+  (let ((len (length fmt))
+       (i 0)
+       (res "")
+       (arguments args))
+    (while (< i len)
+      (let ((c (char fmt i)))
+       (if (char= c #\~)
+           (let ((next (char fmt (incf i))))
+             (cond
+               ((char= next #\~)
+                (setq res (concat res "~")))
+               ((char= next #\%)
+                (setq res (concat res *newline*)))
+               (t
+                (format-special next (car arguments))
+                (setq arguments (cdr arguments)))))
+           (setq res (concat res (char-to-string c))))
+       (incf i)))
+    (if destination
+       (progn
+         (write-string res)
+         nil)
+       res)))
 
 
-  (defun format-special (chr arg)
-    chr))
+ (defun format-special (chr arg)
+   chr))