为什么 Common Lisp 中的包名称和导出使用未驻留的符号?
截屏 (存档博客)在 Common List 上,作者 (Alexander Lehmann) 使用未驻留的符号作为包名称和导出。
(defpackage #:foo
(:use :cl)
(:export #:bar
#:baz))
(in-package #:foo)
他还在匿名函数前面使用了尖号。
(defun transposed (m)
(make-instance 'matrix
:rows (matrix-cols m)
:cols (matrix-rows m)
:generator #'(lambda (i j) (matrix-at m j i))))
在Practical Common Lisp一书中,尖号不用于包名称和导出我读过。
在这些情况下使用未驻留符号(锐号)的原因是什么?
In a screen cast (archived blog) on Common List the author (Alexander Lehmann) uses uninterned symbols for package names and exports.
(defpackage #:foo
(:use :cl)
(:export #:bar
#:baz))
(in-package #:foo)
He also uses the sharp sign in front of anonymous functions.
(defun transposed (m)
(make-instance 'matrix
:rows (matrix-cols m)
:cols (matrix-rows m)
:generator #'(lambda (i j) (matrix-at m j i))))
In the book Practical Common Lisp the sharp sign isn't used for package names and exports as far as I have read.
What's the reason for using the uninterned symbols (the sharp sign) in these cases?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用驻留符号会污染您当前所在的包,这些符号仅用于其名称:
未驻留符号不会这样做:
您也可以直接使用字符串,但由于您通常处理大写符号名称,它们写起来不太方便:
示例
为了说明问题,请考虑以下交互:
Using an interned symbol pollutes the package you're currently in with symbols that are only used for their names anyway:
Uninterned symbols don't do that:
You can also use strings directly, but since you're usually dealing with uppercase symbol names, they are less convenient to write:
Example
To illustrate the problem, consider the following interaction:
#'
是function
运算符的简写(在 Practical Common Lisp 书中多次使用)。#'
is a shorthand for thefunction
operator (this is used a few times in the Practical Common Lisp book).