Common Lisp Keyword list

Where can I find a list of the common Lisp keywords, that's the list of reserved words used in Common Lisp, words like ash, setf, etc.. It would be nice if the list had the usage of the keywords, anyway, all I can find are some of the keywords scattered around in example programs all over the net. I can't do a search on a keyword unless I already know the keyword, and I cant know the keyword unless it's in a list somewhere.

Thanks


If by keyword, you mean the language defined operators, functions, and macros, you can get a list of those symbols by doing:

(let (result) 
  (do-external-symbols (s :common-lisp) 
    (push s result)) 
  (sort result #'string<))

(I am not going to showing the full result list of 978 symbols here). You can read about each of them in the CLHS, in particular, check the symbol index.


@Dirk is right — enumerating the symbols in the Common-Lisp package is the most direct way to answer the question you actually asked.

You can also “search” for a symbol using (among other things) apropos , but for funky “legacy” symbols like ash and setf you might never guess the name. Hopefully early on you'll check out the use of documentation and describe as well.

Assuming you're using some kind of IDE, like Emacs+Slime, you can also use the Inspector to examine a Package. eg, (swank:inspect-in-emacs 'common-lisp) from a *slime-repl window, or pick SLIME → Debugging → Inspect from the menu. You'll get something like:

#<SYMBOL {100F56698F}>
--------------------
Its name is: "COMMON-LISP"
It is unbound.
It has no function value.
It is internal to the package: COMMON-LISP-USER [export] [unintern]
Property list: NIL
It names the package: #<PACKAGE "COMMON-LISP">

Click on the #<Package…> link to view its info; there should be hyperlinks for all the symbols in that package. Different IDE's may present the information in their own way, but most of them are quite similar to the above.


As a side note, "keyword" in Common Lisp refers to something different than in other languages- a symbol in the keyword package. You can spot them because they start with a colon. Generally speaking, they play a similar role as enums in C- they are a name for some unique but unimportant value, so you can cheaply test for them.

Symbols in Common Lisp are used for a lot of things, but the basic idea of them is they are a data type that represents the actual identifiers of other languages, like the name of a variable (as opposed to its contents). In Common Lisp, code to be run goes through two stages- reading, which converts the text of the program into a data structure (and uses symbols to represent identifiers), and evaluation, which actually runs the program stored in the data structure. When the evaluator comes across a symbol, it looks up the value of the variable named by that symbol. Keywords, however, have an interesting property- they are self evaluating, when the evaluator comes across them it doesn't look up their "value", it just keeps the raw symbol object. Combine this with the fact that the reader keeps track of all the previously read symbols so that when it reads an identifier a second time it just returns the existing symbol object, you have the same effect of enums that I mentioned earlier, a named unique value that's cheap to test for. Keywords are used pretty much anywhere in lisp that you want to give a name for something- the keys in hash tables (although you could use anything that compares equal for this, keywords are just convenient), when you want to explicitly name which arguments you're passing to a function, etc.

链接地址: http://www.djcxy.com/p/52368.html

上一篇: 在mongodb中存储图形

下一篇: Common Lisp关键字列表