quicklisp在windows+emacs+slime+sbcl下无法使用的问题

quicklisp在windows+emacs+slime+sbcl下无法使用的问题。可能有初学common lisp的同学会碰到,希望有用。


问题:sbcl+quicklisp在命令行环境下使用正常,但是在emacs+slime下无法使用quicklisp

原因

sbcl的系统初始化文件内容如下(.sbclrc):

;;; The following lines added by ql:add-to-init-file:
#-quicklisp
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
                                       (user-homedir-pathname))))
  (when (probe-file quicklisp-init)
    (load quicklisp-init)))

其中出问题的部分是(user-homedir-pathname)

在sbcl命令行下执行结果:

* (user-homedir-pathname)

#P"C:/Documents and Settings/user/"

在emacs上slime下执行结果:

<pre name="code" class="html"> * (user-homedir-pathname)

#P"C:/Documents and Settings/user/Application Data/"
 两个命令执行的结果不同,所以sbcl在初始化quicklisp的时候,找 
"quicklisp/setup.lisp"使用的路径不同,因为我的quicklisp是在sbcl命令行下安装的,所以在emacs下找不到,quicklisp在emacs+slime下也就无法使用。 

下面代码是sbcl对函数user-homedir-pathname的实现,可以看出sbcl是根据系统的环境变量 HOME/USERPROFILE/HOMEPATH/HOMEDRIVE来计算的。查看系统环境变量(set命令)没有设置HOME,但是有HOMEPATH.

(defun user-homedir-namestring (&optional username)
  (flet ((not-empty (x)
           (and (not (equal x "")) x)))
    (if username
        (sb!unix:user-homedir username)
        (or (not-empty (posix-getenv "HOME"))
            #!+win32
            (not-empty (posix-getenv "USERPROFILE"))
            #!+win32
            (let ((drive (not-empty (posix-getenv "HOMEDRIVE")))
                  (path (not-empty (posix-getenv "HOMEPATH"))))
              (and drive path
                   (concatenate 'string drive path)))
            #!-win32
            (not-empty (sb!unix:uid-homedir (sb!unix:unix-getuid)))
            (error "Couldn't find home directory.")))))

;;; (This is an ANSI Common Lisp function.)
(defun user-homedir-pathname (&optional host)
  #!+sb-doc
  "Return the home directory of the user as a pathname. If the HOME
environment variable has been specified, the directory it designates
is returned; otherwise obtains the home directory from the operating
system. HOST argument is ignored by SBCL."
  (declare (ignore host))
  (values
   (parse-native-namestring
    (or (user-homedir-namestring)
        #!+win32
        (sb!win32::get-folder-namestring sb!win32::csidl_profile))
    *physical-host*
    *default-pathname-defaults*
    :as-directory t)))

为什么emacs和命令行下获取到的路径不一样呢,在emacs+slime下执行

* (posix-getenv "HOME")

"C:\\Documents and Settings\\user"

在sbcl命令行执行

*  (posix-getenv "HOME")

NIL

明显,emacs自动设置了环境变量HOME,在emacs环境下执行sbcl自动继承了这个环境变量。而命令行执行运行sbcl没有这个变量。所以两边不一样。


解决办法: 在系统目录中加入HOME变量,设置为C:\Documents and Settings\user.




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值