How to change SBCL's current directory?

2020-06-03 03:36发布

It is very easy to change CLisp's current working directory:

>cat ~/.clisprc.lisp 
;;; 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)))

(cd "/media/E/www/qachina/db/doc/money")
(load "money")

However, it seems there is no cd similar function in SBCL. How can this be done with SBCL?

5条回答
祖国的老花朵
2楼-- · 2020-06-03 03:56

Had the same question. Turns out

(setf *default-pathname-defaults* (truename "./subdir"))

changes load path to subdir. If you don't want relative path, then

(setf *default-pathname-defaults* (truename "/absolute/path"))
查看更多
forever°为你锁心
3楼-- · 2020-06-03 04:06

Now i use rlwrap to run SBCL and solves this problem

$"cat ~/bin/sb"
breakchars="(){}[],^%$#@\"\";:''|\\"

cd /media/E/www/qachina/db/doc/money/
exec rlwrap --remember -c -b "$breakchars"  -f "$HOME"/.sbcl_completions sbcl "$@"

then run sb.

查看更多
劳资没心,怎么记你
4楼-- · 2020-06-03 04:10
(setf *default-pathname-defaults* #P"/New/Absolute/Path/")
查看更多
神经病院院长
5楼-- · 2020-06-03 04:11

Right now, better answer is: use (uiop:chdir "some/path").

Or you can use this function to change directory temporarily:

(uiop:call-with-current-directory "some/path" (lambda () (do-the-job))

Or this macro for more convenient way:

(uiop:with-current-directory ("some/path") (do-the-job))

查看更多
6楼-- · 2020-06-03 04:14
CL-USER> (sb-posix:chdir "/home/apugachev")
0
CL-USER> (sb-posix:getcwd)
"/home/apugachev"
CL-USER> (sb-posix:chdir "/tmp/")
0
CL-USER> (sb-posix:getcwd)
"/tmp"
查看更多
登录 后发表回答