我有一个问题,这是否是语言有意为之的,或者这是否是 Common Lisp 中的一种意外/不需要的行为/BUG。
但是,我在 CLISP 和 SBCL 中都观察到了它:
我想,
(make-pathname :directory (pathname-directory my-directory-path))
在所有操作系统中都是/应该是免费的。
在 Linux 和 MacOS 中是这样。
但是在 Windows 中,您会丢失有关驱动器盘符的信息:
(pathname-directory #P"C:/Users/me/test/")
;;=> (:ABSOLUTE "Users" "me" "test") ;;=> Drive letter "c:" is lost!
然而,如果您使用
~
,则可以保留它。
(pathname-directory #P"~/test/")
;;=> (:ABSOLUTE :HOME "test")
(make-pathname :directory (pathname-directory #P"~/test/"))
;;=> #P"~/test/" ;; no information loss!
(make-pathname :directory (pathname-directory #P"c:/Users/me/test/"))
;;=> #P"/Users/me/test/" ;;=> information loss - and not only that
;; it became an invalid path now, since the drive letter is lost!
这实际上不是语言规范中的一个错误吗? (因为 Windows 不存在之类的?)。
Unix 没有任何类似于驱动器号的东西,所以说它保留在 Unix 上是没有意义的。
我希望驱动程序字母与 CL 路径名中的
device
字段相对应。所以你也需要复制它:
(MAKE-PATHNAME :directory (pathname-directory my-directory-path)
:device (pathname-device my-directory-path))