X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=gacela_misc.lisp;h=bd7027a182b4fcbf773ad84f203e26e02e91faca;hb=15dc6f156f90086f1f82655b43183f0d8647fa0e;hp=419181b7680236407ec82526a376eb1e475466c9;hpb=a5498a39db21d35ab8090f154944550def25f68e;p=gacela.git diff --git a/gacela_misc.lisp b/gacela_misc.lisp index 419181b..bd7027a 100755 --- a/gacela_misc.lisp +++ b/gacela_misc.lisp @@ -14,7 +14,6 @@ ;;; You should have received a copy of the GNU General Public License ;;; along with this program. If not, see . - (in-package :gacela) (defconstant INFINITY MOST-POSITIVE-LONG-FLOAT) @@ -69,15 +68,37 @@ (t (power (* p 2) n))))) (power 1 n))) -(defmacro mapcconst (type c-type name) - (let ((c-header (concatenate 'string c-type " gacela_" name " (void)")) - (c-body (concatenate 'string "return " name ";")) - (c-name (concatenate 'string "gacela_" name)) - (lisp-name (intern (string-upcase name)))) - `(progn - (defcfun ,c-header 0 ,c-body) - (defentry ,lisp-name () (,type ,c-name)) - (eval-when (load) (defconstant ,lisp-name (,lisp-name)))))) +(defmacro secure-block (output-stream &rest forms) + (let ((error-handler #'si::universal-error-handler)) + `(block secure + (defun si::universal-error-handler (error-name correctable function-name continue-format-string error-format-string &rest args) + ,(when output-stream + `(write-line + (cond ((eq error-name :WRONG-TYPE-ARGUMENT) (string error-name)) + (t error-format-string)) + ,output-stream)) + (setf (symbol-function 'si::universal-error-handler) ,error-handler) + (return-from secure)) + (let (result-eval) + (setq result-eval (progn ,@forms)) + (setf (symbol-function 'si::universal-error-handler) ,error-handler) + result-eval)))) + +(defmacro persistent-let (name vars &rest forms) + (labels ((get-vars (vars) + (cond ((null vars) nil) + (t (cons (if (consp (car vars)) (caar vars) (car vars)) + (get-vars (cdr vars))))))) + + `(let ,(cond ((functionp name) + (let ((old-vars (funcall name))) + (cond ((equal (get-vars vars) (get-vars old-vars)) old-vars) + (t vars)))) + (t vars)) + (defun ,name () + ,(let ((lvars (get-vars vars))) + `(mapcar (lambda (x y) (list x y)) ',lvars ,(cons 'list lvars)))) + ,@forms))) ;Geometry (defun dotp (dot)