需要模块时,名称应该是字符串、符号还是关键字?
When requiring modules, should the name be a string, symbol, or keyword?
以下有什么区别?
(require "asdf") ; String.
(require 'asdf) ; Symbol.
(require :asdf) ; Keyword.
需要模块时应该使用哪个?
require
的参数是一个 string designator 即
a designator for a string; that is, an object that denotes a string and that is one of: a character (denoting a singleton string that has the character as its only element), a symbol (denoting the string that is its name), or a string (denoting itself).
所以以上任何一个都可以。 然而,require
被定义为使用string=
对模块名称进行比较,这意味着大小写很重要。所以这意味着 (require 'asdf)
与 (require :ASDF)
相同,与 (require "ASDF")
相同,但 而非 与 (require "asdf")
相同。 (实际上,ASDF 将 "asdf"
和 "ASDF"
添加到 *modules*
中,因此两者都可以工作。)
就我个人而言,我使用关键字符号,所以 (require :asdf)
、(provide :spotbat)
,这意味着 *modules*
总是以大写字符串结尾。
我发现使用 string=
来比较模块名称的决定有点烦人,但现在就是这样,而且它还与其他各种约定兼容:例如,包名称是大小写敏感的。理论上,它会允许,例如,在同一图像中与 CL 一起存在区分大小写的小写首选语言((find-package "cl")
可能是导出其所有符号的包)。
此答案特定于 ASDF。
加载 ASDF 的推荐方法是使用 (require "asdf")
(即使用小写字符串)。根据 ASDF manual,第 3 节(“加载 ASDF”):
The recommended way to load ASDF is via:
(require "asdf")
脚注说:
NB: all implementations except GNU CLISP also accept (require "ASDF")
, (require 'asdf)
and (require :asdf)
. For portability’s sake, you should use (require "asdf")
.
以下有什么区别?
(require "asdf") ; String.
(require 'asdf) ; Symbol.
(require :asdf) ; Keyword.
需要模块时应该使用哪个?
require
的参数是一个 string designator 即
a designator for a string; that is, an object that denotes a string and that is one of: a character (denoting a singleton string that has the character as its only element), a symbol (denoting the string that is its name), or a string (denoting itself).
所以以上任何一个都可以。 然而,require
被定义为使用string=
对模块名称进行比较,这意味着大小写很重要。所以这意味着 (require 'asdf)
与 (require :ASDF)
相同,与 (require "ASDF")
相同,但 而非 与 (require "asdf")
相同。 (实际上,ASDF 将 "asdf"
和 "ASDF"
添加到 *modules*
中,因此两者都可以工作。)
就我个人而言,我使用关键字符号,所以 (require :asdf)
、(provide :spotbat)
,这意味着 *modules*
总是以大写字符串结尾。
我发现使用 string=
来比较模块名称的决定有点烦人,但现在就是这样,而且它还与其他各种约定兼容:例如,包名称是大小写敏感的。理论上,它会允许,例如,在同一图像中与 CL 一起存在区分大小写的小写首选语言((find-package "cl")
可能是导出其所有符号的包)。
此答案特定于 ASDF。
加载 ASDF 的推荐方法是使用 (require "asdf")
(即使用小写字符串)。根据 ASDF manual,第 3 节(“加载 ASDF”):
The recommended way to load ASDF is via:
(require "asdf")
脚注说:
NB: all implementations except GNU CLISP also accept
(require "ASDF")
,(require 'asdf)
and(require :asdf)
. For portability’s sake, you should use(require "asdf")
.