X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fprimordial-extensions.lisp;fp=src%2Fcode%2Fprimordial-extensions.lisp;h=d9d0d0e6d7b7b8112b23906b9dcde64a7235b061;hb=260a9146f02374a9cfbd9deb53283ee493f3729f;hp=087968c2daf5b7c724ba558c40e3c49b4e6fae7f;hpb=b841aa690bada10da8c8db6eec361e3eeef0492c;p=sbcl.git diff --git a/src/code/primordial-extensions.lisp b/src/code/primordial-extensions.lisp index 087968c..d9d0d0e 100644 --- a/src/code/primordial-extensions.lisp +++ b/src/code/primordial-extensions.lisp @@ -134,6 +134,20 @@ (gensym (format nil "~A[~S]" name block-name)) (gensym name)))) + +;;; Compile a version of BODY for all TYPES, and dispatch to the +;;; correct one based on the value of VAR. This was originally used +;;; only for strings, hence the name. Renaming it to something more +;;; generic might not be a bad idea. +(defmacro string-dispatch ((&rest types) var &body body) + (let ((fun (gensym "STRING-DISPATCH-FUN-"))) + `(flet ((,fun (,var) + ,@body)) + (declare (inline ,fun)) + (etypecase ,var + ,@(loop for type in types + collect `(,type (,fun (the ,type ,var)))))))) + ;;; Automate an idiom often found in macros: ;;; (LET ((FOO (GENSYM "FOO")) ;;; (MAX-INDEX (GENSYM "MAX-INDEX-")))