X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fearly-extensions.lisp;h=5163fe16b0b9d0698aa284b8b7e6796974f244eb;hb=acce826c593a188b231b7b7918c752bda21d0201;hp=e4fa9c580b3ffc771bff6a791e1948a78938f83b;hpb=4ae1b794a5d6a90794468cf8017f5307f2c30dfe;p=sbcl.git diff --git a/src/code/early-extensions.lisp b/src/code/early-extensions.lisp index e4fa9c5..5163fe1 100644 --- a/src/code/early-extensions.lisp +++ b/src/code/early-extensions.lisp @@ -560,6 +560,19 @@ ,@(values-names)) (values ,@(values-names))) (values ,@(values-names)))))))))))) + +(defmacro define-cached-synonym + (name &optional (original (symbolicate "%" name))) + (let ((cached-name (symbolicate "%%" name "-cached"))) + `(progn + (defun-cached (,cached-name :hash-bits 8 + :hash-function (lambda (x) + (logand (sxhash x) #xff))) + ((args equal)) + (apply #',original args)) + (defun ,name (&rest args) + (,cached-name args))))) + ;;;; package idioms @@ -592,7 +605,8 @@ (defun legal-fun-name-p (name) (or (symbolp name) (and (consp name) - (eq (car name) 'setf) + (or (eq (car name) 'setf) + (eq (car name) 'sb!pcl::class-predicate)) (consp (cdr name)) (symbolp (cadr name)) (null (cddr name))))) @@ -606,15 +620,20 @@ :format-control "invalid function name: ~S" :format-arguments (list name)))) -;;; Given a function name, return the name for the BLOCK which -;;; encloses its body (e.g. in DEFUN, DEFINE-COMPILER-MACRO, or FLET). +;;; Given a function name, return the symbol embedded in it. +;;; +;;; The ordinary use for this operator (and the motivation for the +;;; name of this operator) is to convert from a function name to the +;;; name of the BLOCK which encloses its body. +;;; +;;; Occasionally the operator is useful elsewhere, where the operator +;;; name is less mnemonic. (Maybe it should be changed?) (declaim (ftype (function ((or symbol cons)) symbol) fun-name-block-name)) (defun fun-name-block-name (fun-name) (cond ((symbolp fun-name) fun-name) ((and (consp fun-name) - (= (length fun-name) 2) - (eq (first fun-name) 'setf)) + (legal-fun-name-p fun-name)) (second fun-name)) (t (error "not legal as a function name: ~S" fun-name)))) @@ -1015,3 +1034,17 @@ which can be found at .~:@>" (warn "using deprecated ~S~@[, should use ~S instead~]" bad-name good-name)) + +;;; Anaphoric macros +(defmacro awhen (test &body body) + `(let ((it ,test)) + (when it ,@body))) + +(defmacro acond (&rest clauses) + (if (null clauses) + `() + (destructuring-bind ((test &body body) &rest rest) clauses + (once-only ((test test)) + `(if ,test + (let ((it ,test)) (declare (ignorable it)),@body) + (acond ,@rest))))))