From bff224550a8cee9e2571a2cc8f62bde0a7ef54a5 Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Thu, 26 Mar 2020 05:29:26 -0400 Subject: [PATCH] first --- printf.fasl | Bin 0 -> 3889 bytes printf.lisp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 printf.fasl create mode 100644 printf.lisp diff --git a/printf.fasl b/printf.fasl new file mode 100644 index 0000000000000000000000000000000000000000..169f68c876557c5ca3c8afaa0b798ce5fe3f60f4 GIT binary patch literal 3889 zcmbVPYiu0V6`q;BcOSMlyC!KKN+M6jYsbWF>@_3`#R(qojy==NW3vwusMFT5*N(wn z8}BX&qCs)IZZo=C6{8|SD^-ASM1NKJft1jeTB%D2wE%}ckSVPTEploEPJfUXXxwvW zW=SOIpRTlb&OP_M?wxzSbEbA%Qz19nbYvjglsnQh$cMwZp3#Akd_^taAtu!dp6?kR z8W|YO^zwb9!$Z8#baZ$q(=<5TpUF1GhIG_v@mjM8i=dA<=nUjP4gZrLby5_a`YMB_|{?Mya%}M2(nqdlJDUYOH1I zVp4}DMiWLd7&SD_(8H>djEB=nDPj1zctX)r9s5ucgZO=#QG-MktcFtwQHzHYk%%xh zNh4zz&EH`pG%+PiKWsCMZH{(0WrUqI<&d+sor%g)bbmOOr0!Bp^$97N5)`^G_-R|M zh{7FdJ(^Ms9l1_n&7Vv`Fr8YZC2RP&`@}?Y9CJxGga%O>YXix$f{QBnqJ|CvjcAf_ zu?Qni7l$XYUTN7zF0Hz}^CvN?L{-RN#K>EXJk`jJDthn!zuzhrUjC&1eYy`Wice zXv-yW<;6f?;`el!NXs&bvvMgGT9(H@;(tSQhlMC|2wiV0G_%uY^b`_=u6O7BwR5jx(swuNdWT+v}&H7~W&+CVO zJKM?At;}{Zv%v?OEtgBbpjK}A1%a+%ybO!(SO-HGZ5G&*_WDD(nZtWrNe{h{T3j{! z%{05xy0L*vNO4t+N?}N!eRpb=QPoIFg7UKc77Ra=)(u{nGtOVfw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/printf.lisp b/printf.lisp new file mode 100644 index 0000000..14914b9 --- /dev/null +++ b/printf.lisp @@ -0,0 +1,38 @@ +;;;; Make a macro that is like C's printf statement + +(defmacro printf (string &rest vars) + `(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)))) + ) + + + + + + +