X-Git-Url: http://git.kpe.io/?p=kmrcl.git;a=blobdiff_plain;f=macros.lisp;h=c83b3b64a19f9f9be26f9dd96daa9ed9213f6f6d;hp=9b6150a470dc9597470fe8ad2ba8e303e9c3e853;hb=5f3fba52fd7c9984a7f797c4720ec93799d6d786;hpb=526eef1b59e071cbb4ecd35f73a14c1a3f8e32b6 diff --git a/macros.lisp b/macros.lisp index 9b6150a..c83b3b6 100644 --- a/macros.lisp +++ b/macros.lisp @@ -147,6 +147,15 @@ ,@body)) +(defmacro time-seconds (&body body) + (let ((t1 (gensym))) + `(let ((,t1 (get-internal-real-time))) + (values + (progn ,@body) + (coerce (/ (- (get-internal-real-time) ,t1) + internal-time-units-per-second) + 'double-float))))) + (defmacro time-iterations (n &body body) (let ((i (gensym)) (count (gensym))) @@ -239,3 +248,24 @@ ,@(mapcar (lambda (x) (list 'ignore-errors x)) forms))) + +(defmacro ppmx (form) + "Pretty prints the macro expansion of FORM." + `(let* ((exp1 (macroexpand-1 ',form)) + (exp (macroexpand exp1)) + (*print-circle* nil)) + (cond ((equal exp exp1) + (format t "~&Macro expansion:") + (pprint exp)) + (t (format t "~&First step of expansion:") + (pprint exp1) + (format t "~%~%Final expansion:") + (pprint exp))) + (format t "~%~%") + (values))) + +(defmacro defconst (symbol value &optional doc) + `(defconstant ,symbol (if (boundp ',symbol) + (symbol-value ',symbol) + ,value) + ,@(when doc (list doc))))