X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=static.el;h=a42d816c25066f9d4acea8415ef24544497de09d;hb=329b62714dec924ad4ea1e664f4b0e90391bc513;hp=a47eb0548791cc71657d411e312b4ca0beb4e3b9;hpb=64c72f840d56c5f73d519205235d0d93834bae77;p=elisp%2Fapel.git diff --git a/static.el b/static.el index a47eb05..a42d816 100644 --- a/static.el +++ b/static.el @@ -26,52 +26,64 @@ (put 'static-if 'lisp-indent-function 2) (defmacro static-if (cond then &rest else) - "`if' expression but COND is evaluated at compile-time." + "Like `if', but evaluate COND at compile time." (if (eval cond) then (` (progn (,@ else))))) (put 'static-when 'lisp-indent-function 1) (defmacro static-when (cond &rest body) - "`when' expression but COND is evaluated at compile-time." + "Like `when', but evaluate COND at compile time." (if (eval cond) (` (progn (,@ body))))) (put 'static-unless 'lisp-indent-function 1) (defmacro static-unless (cond &rest body) - "`unless' expression but COND is evaluated at compile-time." + "Like `unless', but evaluate COND at compile time." (if (eval cond) nil (` (progn (,@ body))))) (put 'static-condition-case 'lisp-indent-function 2) (defmacro static-condition-case (var bodyform &rest handlers) - "`condition-case' expression but BODYFORM is evaluated at compile-time." + "Like `condition-case', but evaluate BODYFORM at compile time." (eval (` (condition-case (, var) (list (quote quote) (, bodyform)) (,@ (mapcar (if var - (lambda (h) - (` ((, (car h)) - (list (quote funcall) - (lambda ((, var)) (,@ (cdr h))) - (list (quote quote) (, var)))))) - (lambda (h) - (` ((, (car h)) (quote (progn (,@ (cdr h)))))))) + (function + (lambda (h) + (` ((, (car h)) + (list (quote funcall) + (function (lambda ((, var)) (,@ (cdr h)))) + (list (quote quote) (, var))))))) + (function + (lambda (h) + (` ((, (car h)) (quote (progn (,@ (cdr h))))))))) handlers)))))) -(defmacro static-defconst (symbol initvalue docstring) - "`defconst' expression but INITVALUE is evaluated at compile-time. +(put 'static-defconst 'lisp-indent-function 'defun) +(defmacro static-defconst (symbol initvalue &optional docstring) + "Like `defconst', but evaluate INITVALUE at compile time. -The variable SYMBOL can be referenced at either compile-time or run-time." +The variable SYMBOL can be referred at both compile time and run time." (let ((value (eval initvalue))) (eval (` (defconst (, symbol) (quote (, value)) (, docstring)))) (` (defconst (, symbol) (quote (, value)) (, docstring))))) +(defmacro static-cond (&rest clauses) + "Like `cond', but evaluate CONDITION part of each clause at compile time." + (while (and clauses + (not (eval (car (car clauses))))) + (setq clauses (cdr clauses))) + (if clauses + (cons 'progn (cdr (car clauses))))) + ;;; @ end ;;; -(provide 'static) +(require 'product) +(product-provide (provide 'static) (require 'apel-ver)) ;;; static.el ends here