Emacs Lisp:评估列表中的变量 [英] Emacs Lisp: evaluate variable in alist

查看:89
本文介绍了Emacs Lisp:评估列表中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能很愚蠢,但是我没有足够的Elisp知识来了解报价和评估方面的情况。

This is probably silly but I don't have enough Elisp knowledge to understand what is going on with respect to quoting and evaluation.

假设我有此Elisp代码:

Suppose I have this Elisp code:

(add-to-list 'default-frame-alist '(width . 100))
(add-to-list 'default-frame-alist '(height . 50))

这将导致预期的默认框架alist值:

It will result in the expected default-frame-alist value:

((height 50)
 (width 100))

但是现在如果我有这个话:

But now if I have this:

(setq my-frame-width 100)
(setq my-frame-height 50)
(add-to-list 'default-frame-alist '(width . my-frame-width))
(add-to-list 'default-frame-alist '(height . my-frame-height))

这将导致-

((height my-frame-height)
 (width my-frame-width))

并且,从框架几何形状来看,从不评估那些变量。如何使我的框架宽度和高度的实际值出现在此列表中?我的报价太多了吗?但是我无法从添加到列表的评估中删除任何内容。

and, judging from the frame geometry, never evaluates those variables. How do I make the actual values of my-frame-width and height appear in this alist? Do I have too many quotes? But I cannot remove any from the add-to-list evaluations...

推荐答案

尝试一下:

(setq my-frame-width 100)
(setq my-frame-height 50)
(add-to-list 'default-frame-alist `(width . ,my-frame-width))
(add-to-list 'default-frame-alist `(height . ,my-frame-height))

使用反引号代替引号允许您使用来强制执行参数的求值。

Using backquote instead of quote allows you to use , to force the evaluation of a parameter.

请参阅Elisp参考手册。键入C-x info,搜索elisp参考手册,然后在其中搜索反引号。

See the Elisp reference manual. Type C-x info, search for the elisp reference manual, then search for backquote within that.

这篇关于Emacs Lisp:评估列表中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆