使用包装阴影符号 [英] Use package shadowing symbols
问题描述
例如,我有这个包定义,它笼罩着COMMON-LISP:LISTEN:
For instance I have this package definition which shadows COMMON-LISP:LISTEN :
(defpackage :shadows
(:use :common-lisp)
(:shadow #:listen)
(:export #:listen))
然后我想从另一个软件包中使用这个软件包,例如
And then I want to use this package from another package, say
(defpackage :light
(:use :common-lisp
:shadows))
如果在使用该软件包时实际上无法覆盖Common Lisp符号,那么阴影的作用是什么?
What is the purpose of shadow if I cannot actually override Common Lisp symbols when using the package ?
推荐答案
好的,因此实际上有一种方便的方法.
OK so there actually is a handy way to do this.
在多阴影包中,我导出了shadowing-import-from
函数.看起来像这样:
In my many-shadows package I export a shadowing-import-from
function. It looks like this :
(defun shadowing-import-from ()
`(:shadowing-import-from :many-shadows
,@(package-shadowing-symbols :many-shadows)))
然后,在轻量的defpackage中,我只是对其进行READ-EVAL评估:
And then, in the light defpackage I just READ-EVAL it :
(defpackage :light
(:use :common-lisp
:many-shadows)
#.(many-shadows:shadowing-import-from))
因此,很明显,有些东西被遮盖了,我想优先使用来自许多阴影的符号.而且它足够短,可以被实用地记录和使用.
So it is explicit that something was shadowed and that I want to use the symbols from many-shadows in priority. And it is short enough to be documented and used pragmatically.
感谢@sds将我指向:shadowing-import-from
.
Thank you @sds for pointing me to :shadowing-import-from
.
这篇关于使用包装阴影符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!