如何檢視common lisp函式的文件?
阿新 • • 發佈:2019-02-02
Common Lisp有幾百個函式,不可能把所有的函式用法都記得很清楚,所以就希望在編寫程式時可以隨時的檢視函式的文件描述。
首先,我找到documentation函式,其用法是:
(documentation 'symbol 'type)
例如,我想檢視make-hash-table函式,其用法和結果如下:
這個返回結果資訊很好。但是,對於一些函式如random,其返回的內容就很少:CL-USER> (documentation 'make-hash-table 'function) "Create and return a new hash table. The keywords are as follows: :TEST -- Indicates what kind of test to use. :SIZE -- A hint as to how many elements will be put in this hash table. :REHASH-SIZE -- Indicates how to expand the table when it fills up. If an integer, add space for that many elements. If a floating point number (which must be greater than 1.0), multiply the size by that amount. :REHASH-THRESHOLD -- Indicates how dense the table can become before forcing a rehash. Can be any positive number <=1, with density approaching zero as the threshold approaches 0. Density 1 means an average of one entry per bucket."
CL-USER> (documentation 'random 'function)
NIL
所以,我希望找到一種可以檢視任何函式的方法。
最後,我在slime的manual中找到了檢視函式文件的命令:
這個命令,預設情況下,會進行線上的查詢,需要網路連線正常。為了在不方便上網的時候也可以檢視函式文件,我們只需要把Hyperspec文件下載到本地,然後在檔案hypersepc.el中修改變數common-lisp-hyperspec-root的值為你本地的路徑(即存放Hyperspec文件的路徑)。C-c C-d h M-x slime-hyperspec-lookup Lookup the symbol at point in the Common Lisp Hyperspec. This uses the familiar hyperspec.el to show the appropriate section in a web browser. The Hyperspec is found either on the Web or in common-lisp-hyperspec-root, and the browser is selected by browse-url-browser-function. Note: this is one case where C-c C-d h is not the same as C-c C-d C-h.
越來越感覺,只要正確設定好,lisp的互動環境比python的互動環境更強大。