简体   繁体   English

我如何在elisp中最好地使用common-lisp(如果有的话)?

[英]How do I best use common-lisp in elisp (if at all)?

Can someone please explain what the specific issues are with using the cl package in elisp? 有人可以解释一下使用elisp中的cl包的具体问题吗? As a new coder in emacs I feel as though I'm making a mistake whenever I reach for the (require 'cl) option. 作为emacs中的一个新编码器,我觉得好像我在达到(require'cl)选项时犯了一个错误。 I have read and understood the byte-compilation issue with the cl package. 我已经阅读并理解了cl包的字节编译问题。 I have looked at the old arguments and have no wish to revive them. 我看过旧的论点,不想重振它们。 I am also not looking for any generalist comment on whether common-lisp is better than x brand lisp. 我也不是在寻找关于common-lisp是否优于x品牌lisp的通才评论。

What I would like to know is practically how to use common-lisp so that any elisp I write will have a good chance of being accepted by the majority of elisp coders. 我想知道的是几乎如何使用common-lisp,以便我写的任何elisp都有很大机会被大多数elisp编码器接受。 Specifically, should I avoid using common lisp entirely, or are there some parts of the language that are acceptable to everyone and some parts where a good majority of coders would snigger and scoff at? 具体来说,我是否应该完全避免使用普通的lisp,或者是否存在一些人人都可以接受的语言部分以及大多数编码人员会窃听和嘲笑的某些部分?

Without wishing to limit the breadth of the answer, is this: 不希望限制答案的广度,是这样的:

(mapcar (lambda(x) (* x x)) '(1 2 3))

much more acceptable than this: 比这更可接受:

(require 'cl)
(loop for el in '(1 2 3) collect (* el el))

While using a lot of third-party libraries and writing some of my own eLisp code, I never encountered the situation when using CL package resulted in a name conflict. 在使用大量第三方库并编写我自己的一些eLisp代码时,我从未遇到过使用CL包导致名称冲突的情况。 So, I'd be tempted to say that the argument against using CL is nothing but puritanism (in the original sense of the word, not meaning the religious side of things). 因此,我很想说反对使用CL的论点只不过是清教主义(在原始意义上,并不意味着事物的宗教方面)。

But, if you are planning on a very long time support and you want to have some sort of a backup, here's what I would do (but I'm not doing that myself, because fixing things once they are broken seems to be a better tactic). 但是,如果你计划在很长一段时间内获得支持,并希望得到某种备份,那么这就是我要做的事情(但我自己并没有这样做,因为一旦它们被破坏就修复它们似乎更好战术)。 For the functions in CL package that you are using, create a special file, where you defalias all of them to have a cl- prefix. 对于CL包的功能,你正在使用,创建一个特殊的文件,在这里你defalias个个有cl-前缀。 So, for example, instead of having a (position ...) you would have (cl-position ...) . 因此,例如,您将拥有(cl-position ...) (position ...)而不是(cl-position ...) Theoretically will save you the problem of forward compatibility. 从理论上讲,它将为您节省向前兼容性的问题。 However functions don't get removed instantly, you'll get a warning ahead of time of them being deprecated, and will have a lot of time to update. 但是,函数不会立即被删除,您将在它们被弃用之前得到警告,并且将有大量时间进行更新。 Up to you, really. 真的,由你决定。

Loop macro in Common Lisp is a controversy all by itself, it is not a typical construct for the language and that's why, for example, the iterate library exists. Common Lisp中的循环宏本身就是一个争议,它不是语言的典型构造,这就是为什么,例如迭代库存在的原因。 It also requires that you learn "the loop mini-language" to use it well, which is sort of a small domain-specific language, and there's really no requirement that this kind of construct use one. 它还要求你学习“循环迷你语言”以便很好地使用它,这是一种特定于领域的小语言,并且实际上并不要求这种构造使用它。 BUT, loop has its strong sides. 但是,循环有其强大的一面。 List processing functions such as mapcar or reduce will serve you well in more trivial cases, like the one you have in your example, but in the less trivial cases loop is going to be a better and also less verbose way of doing the same thing. 列表处理函数(例如mapcarreduce将在更简单的情况下为您提供良好的服务,就像您在示例中所拥有的那样,但在不太简单的情况下, loop将是一种更好,也更简洁的方式来做同样的事情。

Have you read the macros section of the manual? 您是否阅读过本手册的宏部分 Using macros such as your loop example is perfectly okay. 使用诸如loop示例之类的宏是完全可以的。

But you would use eval-when-compile around the require. 但是你可以在require周围使用eval-when-compile

In fact (eval-when-compile (require 'cl)) appears 66 times just in the root lisp folder in my Emacs. 事实上(eval-when-compile (require 'cl))出现在我的Emacs的root lisp文件夹中66次。

Unless you plan to integrate your code in Emacs use the CL package, and put this snippet in your .emacs to disable the warnings. 除非您计划将代码集成到Emacs中,否则请使用CL包,并将此代码段放在.emacs以禁用警告。

(byte-compile-disable-warning 'cl-functions)

Note: You can find some advices on elisp programming on nicferrier's blog . 注意:您可以在nicferrier的博客上找到关于elisp编程的一些建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM