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

查看:24
本文介绍了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.

要了解有关符号的更多信息,请阅读符号 文档(特别是 Symbol Components 符号具有名称、值、函数定义和属性列表).

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.

为了使这两种情况起作用,您实际上需要变量名,以便您可以修改it指向的内容.

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 指向一个列表:

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,您拥有它的 value).像这样:

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天全站免登陆