Why do some people use keywords for the clauses in the loop macro?

家住魔仙堡 提交于 2019-12-02 00:12:30

问题


Does it solve any problem? According to the first footnote of PCL, if not a keyword it interns the symbol in the current package. As all keywords are interned in the keyword package it would prevent multiple symbols being interned in different packages. But are there any other advantages? What problems does it create? (I'm guessing there must be a problem as it is not the prevalent convention)


回答1:


No, the only advantage is to not end up with extra symbols in whatever package your code is read in.

This isn't a problem in and of itself, but it is one of those things that make (some) elemens of automatic introspection more difficult. If you are careful to use keywords for LOOP "keywords", you can then easily identify the names of all your functions, variables and macros by simply looking at the symbols interned in the package.




回答2:


In lisp-aware editors, keywords are highlighted. Using keywords in loop helps highlight the loop structure.




回答3:


Also from PCL:

Loop keywords is a bit of a misnomer since they aren't keyword symbols. In fact, LOOP doesn't care what package the symbols are from. When the LOOP macro parses its body, it considers any appropriately named symbols equivalent. You could even use true keywords if you wanted--:for, :across, and so on--because they also have the correct name. But most folks just use plain symbols. Because the loop keywords are used only as syntactic markers, it doesn't matter if they're used for other purposes--as function or variable names.

(Peter Seibel, Practical Common Lisp, Chapter 7, Footnote 8.)



来源:https://stackoverflow.com/questions/22473276/why-do-some-people-use-keywords-for-the-clauses-in-the-loop-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!