开发者

Is there a built-in Emacs Lisp form to only set a variable if it is unbound?

开发者 https://www.devze.com 2023-04-02 03:26 出处:网络
I\'ve created the following macro in elisp. It will set the value \"val\" to a variable \"var\" only if the variable is unbound. This exists so variables开发者_开发知识库 set in your .emacs file do no

I've created the following macro in elisp. It will set the value "val" to a variable "var" only if the variable is unbound. This exists so variables开发者_开发知识库 set in your .emacs file do not get trampled over somewhere else.

(defmacro set-ifunbound (var val)
  `(if (not (boundp ',var))
       (setq ,var ,val)
     (identity ,var)))

Surely, this has to be a common pattern. Is there a built in way of doing the same thing?


defvar does exactly that. It assigns a value to a variable only if it's unbound.

0

精彩评论

暂无评论...
验证码 换一张
取 消