X-Git-Url: https://git.distorted.org.uk/~mdw/lisp/blobdiff_plain/b2c12b4eaf6e5c43791d95080a243c35f97ee488..1a50efd8a9e976bf16a29ce381ea38c6b9a39ea1:/mdw-base.lisp diff --git a/mdw-base.lisp b/mdw-base.lisp index 646eb7e..95b79de 100644 --- a/mdw-base.lisp +++ b/mdw-base.lisp @@ -31,7 +31,8 @@ (:export #:unsigned-fixnum #:compile-time-defun #:show - #:stringify #:mappend #:listify #:fix-pair #:pairify + #:stringify #:functionify #:mappend + #:listify #:fix-pair #:pairify #:parse-body #:with-parsed-body #:whitespace-char-p #:slot-uninitialized @@ -65,7 +66,7 @@ "Debugging tool: print the expression X and its values." (let ((tmp (gensym))) `(let ((,tmp (multiple-value-list ,x))) - (format t "~&") + (fresh-line) (pprint-logical-block (*standard-output* nil :per-line-prefix ";; ") (format t "~S = ~@_~:I~:[#~;~:*~{~S~^ ~_~}~]" @@ -83,6 +84,13 @@ (symbol (symbol-name str)) (t (princ-to-string str)))) +(defun functionify (func) + "Convert the function-designator FUNC to a function." + (declare (type (or function symbol) func)) + (etypecase func + (function func) + (symbol (symbol-function func)))) + (defun mappend (function list &rest more-lists) "Apply FUNCTION to corresponding elements of LIST and MORE-LISTS, yielding a list. Return the concatenation of all the resulting lists. Like @@ -127,6 +135,17 @@ t) (t nil))) +(defmacro defconstant* (name value &key doc test) + "Define a constant, like `defconstant'. The TEST is an equality test used + to decide whether to override the current definition, if any." + (let ((temp (gensym))) + `(eval-when (:compile-toplevel :load-toplevel :execute) + (let ((,temp ,value)) + (unless (and (boundp ',name) + (funcall ,(or test ''eql) (symbol-value ',name) ,temp)) + (defconstant ,name ,value ,@(and doc (list doc)))) + ',name)))) + (declaim (ftype (function nil ()) slot-unitialized)) (defun slot-uninitialized () "A function which signals an error. Can be used as an initializer form in