;;;; Make a macro that is like C's printf statement (defmacro printf (string &rest vars) "Pretend to be printf... except preceding dec places" `(format t ,(printf-to-format string) ,@vars)) (defun replace-all (string part replacement &key (test #'char=)) "Returns a new string in which all the occurences of the part is replaced with replacement." (with-output-to-string (out) (loop with part-length = (length part) for old-pos = 0 then (+ pos part-length) for pos = (search part string :start2 old-pos :test test) do (write-string string out :start old-pos :end (or pos (length string))) when pos do (write-string replacement out) while pos))) (defun printf-to-format (string &optional (printf-format '("%s" "%d" "%x" "%f" "%u" "\n")) (lisp-format '("~A" "~D" "~X" "~F" "~D" "~%"))) "Convert printf sytax to format syntax" (cond ((NULL printf-format) (return-from printf-to-format string)) (T (printf-to-format (replace-all string (car printf-format) (car lisp-format)) (cdr printf-format) (cdr lisp-format)))))