emacs lisp中的符号和变量名之间的区别 [英] Difference between symbol and variable name in emacs lisp

查看:115
本文介绍了emacs lisp中的符号和变量名之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道

(add-to-list 'flymake-allowed-file-name-masks
         '("\\.py\\'" flymake-pylint-init))

(add-to-list flymake-allowed-file-name-masks
         '("\\.py\\'" flymake-pylint-init))

这个撇号的清晰含义是什么?

What is the clear meaning of the apostrophe here?

推荐答案

撇号是一个引号,它告诉解释器不解析以下表达式(符号名称)。因此,'add-to-list 获取包含要评估的列表值的符号。

The apostrophe is a quote, which tells the interpreter to not parse the following expression (the symbol name). Thus, 'add-to-list gets the symbol which contains the list value that is intended to be evaluated.

要了解有关符号的更多信息,请阅读符号文档(具体来说,符号组件符号有名称,值,函数定义和属性列表。

To learn more about symbols, read the Symbol documentation (specifically, Symbol Components symbols have names, values, function definitions and property lists).

没有阅读文档,这个是我如何解释它:Emacs lisp的评估策略是通过价值(而不是名称)或参考或其他东西)。如果报价不在,则$ flymake-allowed-file-name-masks 将被评估为一个值, add-to-list 将直接在列表中工作。这将工作,除了以下例外。如果列表为空,则无法更改原始变量指向的内容。出于同样的原因,您将无法将元素添加到列表的前端。

Without reading the documentation, this is how I explain it: Emacs lisp's evaluation strategy is to pass by value (as opposed to by name or reference or something else). If the quote were not there, flymake-allowed-file-name-masks would be evaluated to a value, and add-to-list would have to work directly on the list. This would work, with the following exceptions. If the list were empty, there would be no way to change what the original variable pointed to. For the same reason, you would not be able to add elements to the front of the list.

为了使这两种情况工作,您实际上需要变量名称,以便您可以修改 指向的

To make those two cases work, you actually need the variable name so that you can modify what it points to.

阅读以下内容可能会很有用:评估简介修改列表变量修改现有列表结构

It'd probably be useful to read the following: Introduction to Evaluation, Modifying List Variables, and Modifying Existing List Structures.

如果您熟悉框图,也许这将有所帮助。

If you're familiar with box diagrams, perhaps this will help.

想象一下, some-var po ints to a list:

Imagine that some-var points to a list:

somevar
  |
  |
  v
 --- ---      --- ---      --- ---        
|   |   |--> |   |   |--> |   |   |--> nil
 --- ---      --- ---      --- ---        
  |            |            |             
  |            |            |             
   --> rose     --> violet   --> buttercup

你想把东西放在该列表的前面。

And you wanted to put something on the front of that list.

如果所有你必须使用的是 somevar 中的指针的,那么你最好的在列表的前面放置一个新元素,但是实际上您不能修改 somevar 指向(因为您没有 somevar ,你有它的)。像这样:

If all you have to work with is the value of the pointer in somevar, then the best you can do is put a new element on the front of the list, but you cannot actually modify what somevar points to (because you don't have somevar, you have it's value). Like so:

             somevar
               |
               |
               v
 --- ---      --- ---      --- ---      --- ---        
|   |   |--> |   |   |--> |   |   |--> |   |   |--> nil
 --- ---      --- ---      --- ---      --- ---        
  |            |            |            |             
  |            |            |            |             
   --> tulip     --> rose     --> violet   --> buttercup

所以,要写自己的'add-to-list 函数,你需要变量名。

So, to write your own 'add-to-list function, you need the variable name.

当然,如果你写了'add-to-list 作为,你会没有限制。

Of course, if you wrote 'add-to-list as a macro, you wouldn't have that restriction.

这篇关于emacs lisp中的符号和变量名之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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