+
+(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 #\~)
+ (concatf res "~"))
+ ((char= next #\%)
+ (concatf res *newline*))
+ (t
+ (concatf res (format-special next (car arguments)))
+ (pop arguments))))
+ (setq res (concat res (char-to-string c))))
+ (incf i)))
+ (if destination
+ (progn
+ (write-string res)
+ nil)
+ res)))
+
+
+(defun format-special (chr arg)
+ (case chr
+ (#\S (prin1-to-string arg))
+ (#\a (princ-to-string arg))))