Shammer's Philosophy

My private adversaria

package が変わっても・・・

use-package を使う - Shammerismdefpackage の :use の意味 - Shammerismの続きになるかも。パッケージの使い方で想定していなかった動作を確認。

? (defpackage p1)
#<Package "P1">
? (in-package p1)
#<Package "P1">
? (defun hello () (format t "AAA~%"))
HELLO
? (export 'hello)
T
? (defpackage p2)
#<Package "P2">
? (in-package p2)
#<Package "P2">
? (defun hello () (format t "BBB~%"))
HELLO
? (export 'hello)
T
? (defpackage p3 (:use ccl common-lisp common-lisp-user p1 p2))
> Error: Using #<Package "P1"> in #<Package "P3"> 
>        would cause name conflicts with symbols inherited by that package: 
>        HELLO  P1:HELLO
>        
> While executing: CCL::USE-PACKAGE-1, in process Listener(4).
> Type cmd-/ to continue, cmd-. to abort, cmd-\ for a list of available restarts.
> If continued: Try again to use #<Package "P1"> in #<Package "P3">
> Type :? for other options.
1 > q
? (in-package common-lisp-user)
#<Package "COMMON-LISP-USER">
? (p1:hello)
AAA
NIL
? (p2:hello)
BBB
NIL
? (use-package 'p1)
T
? (use-package 'p2)
> Error: Using #<Package "P2"> in #<Package "COMMON-LISP-USER"> 
>        would cause name conflicts with symbols inherited by that package: 
>        HELLO  P2:HELLO
>        
> While executing: CCL::USE-PACKAGE-1, in process Listener(4).
> Type cmd-/ to continue, cmd-. to abort, cmd-\ for a list of available restarts.
> If continued: Try again to use #<Package "P2"> in #<Package "COMMON-LISP-USER">
> Type :? for other options.
1 > q
? (hello)
AAA
NIL
? (p2:hello)
BBB
NIL
? 

p1:hello と p2:hello はパッケージ名まで含めて考えた場合は別だが、同名の export シンボルを持つパッケージを use-package することはできない。use-package しない場合は、p1:hello と p2:hello は別のものと認識されるが、use-package した場合はそうじゃなくなる。ちょっとやってみて自分でこの文章を書いている間に、そうかと自分で納得できたものの、この結果に遭遇したときはパッケージの意味ないじゃないかと思ってしまった。色々なパッケージから構成される大き目のアプリを書く際には注意しておかないといけない。