X-Git-Url: http://git.kpe.io/?p=kmrcl.git;a=blobdiff_plain;f=macros.lisp;h=d0ba63c629d8e698cc011c6072ce82c20e7d604d;hp=bf2714b86d441eec6f9d0c4bbce5a64f7f539d73;hb=a5f8c5c91b2dc670e196147b08dafa0ca23259e4;hpb=93ac7eed8f69f19013472f078b544be145619ff5 diff --git a/macros.lisp b/macros.lisp index bf2714b..d0ba63c 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))) @@ -254,3 +263,17 @@ (pprint exp))) (format t "~%~%") (values))) + +(defmacro defconstant* (sym value &optional doc) + "Ensure VALUE is evaluated only once." + `(defconstant ,sym (if (boundp ',sym) + (symbol-value ',sym) + ,value) + ,@(when doc (list doc)))) + +(defmacro defvar-unbound (sym &optional (doc "")) + "defvar with a documentation string." + `(progn + (defvar ,sym) + (setf (documentation ',sym 'variable) ,doc))) +