Shammer's Philosophy

My private adversaria

defpackage の :use の意味

use-package を使う - Shammerismでやった、use-package の存在を知って思ったのだが、defpackage の :use のブロックは、ここで指定した package のプレフィックスを不要にするというものではなく、シンボルをインポートするというだけのものではないだろうか。
つまり、common-lisp-user の方で定義したシンボルは package aaa で定義できない・・・いや、待て。そんなわけはない。そうだとしたら何のための package か。
よくわからないが、とりあえずテスト。

? (defpackage aaa
(:use common-lisp))
#<Package "AAA">
? (defparameter hello "Hello, COMMON-LISP-USER")
HELLO
? (in-package aaa)
#<Package "AAA">
? hello
> Error: Unbound variable: HELLO
> While executing: CCL::TOPLEVEL-EVAL, in process Listener(4).
> Type cmd-/ to continue, cmd-. to abort, cmd-\ for a list of available restarts.
> If continued: Retry getting the value of HELLO.
> Type :? for other options.
1 > q
? (defparameter hello "Hello, AAA")
HELLO
? hello
"Hello, AAA"
? common-lisp-user::hello
"Hello, COMMON-LISP-USER"
? *package*
#<Package "AAA">
? (quit)
> Error: Undefined function QUIT called with arguments () .
> While executing: CCL::TOPLEVEL-EVAL, in process Listener(4).
> Type cmd-/ to continue, cmd-. to abort, cmd-\ for a list of available restarts.
> If continued: Retry applying QUIT to NIL.
> Type :? for other options.
1 >

うーん、、、 :use は機能しているんだろうか。

? (defpackage aaa
(:use "COMMON-LISP"))
#<Package "AAA">
? (in-package aaa)
#<Package "AAA">
? (quit)
> Error: Undefined function QUIT called with arguments () .
> While executing: CCL::TOPLEVEL-EVAL, in process listener(1).
> Type :GO to continue, :POP to abort, :R for a list of available restarts.
> If continued: Retry applying QUIT to NIL.
> Type :? for other options.
1 > (common-lisp-user::quit)
$

確認する情報によって、:use に渡す package が何かは決まっていないので、色々試して判断するしかない。

? (defpackage aaa
(:use "COMMON-LISP-USER"))
#<Package "AAA">
? (in-package aaa)
#<Package "AAA">
? (quit)
> Error: Undefined function QUIT called with arguments () .
> While executing: CCL::TOPLEVEL-EVAL, in process listener(1).
> Type :GO to continue, :POP to abort, :R for a list of available restarts.
> If continued: Retry applying QUIT to COMMON-LISP:NIL.
> Type :? for other options.
1 > (common-lisp-user::quit)

:use に渡すのが文字列だとダメなのだろうか。。。

? (defpackage aaa
(:use common-lisp-user))
#<Package "AAA">
? (in-package aaa)
#<Package "AAA">
? (quit)
> Error: Undefined function QUIT called with arguments () .
> While executing: CCL::TOPLEVEL-EVAL, in process listener(1).
> Type :GO to continue, :POP to abort, :R for a list of available restarts.
> If continued: Retry applying QUIT to COMMON-LISP:NIL.
> Type :? for other options.
1 > (common-lisp-user:quit)

> Error: Reader error: No external symbol named "QUIT" in package #<Package "COMMON-LISP-USER"> .
> While executing: CCL::%PARSE-TOKEN, in process listener(1).
> Type :GO to continue, :POP to abort, :R for a list of available restarts.
> If continued: Use the internal symbol CCL:QUIT
> Type :? for other options.
2 > (common-lisp-user::quit)
$

うーん、、、ダメだ。他に思いうかぶアイデアがない。。。まあ、パッケージを使用すればシンボルの重複は回避できるはず。アクセスさせたい情報をきちんと export すればいいはずなので、ここはあまり堀り下げなくてもいいかも。ClozureCL 固有の動作なのかもしれない。