Zach Beane (xach) wrote,

Tilde for SBCL convenience

Every now and then I want to use leading tildes in SBCL pathnames. That is, something like this:

(probe-file "~/.emacs") =>
   #P"/home/xach/.emacs" 
OR #P"/Users/xach/.emacs"
OR #P"/usr/u/xach/.emacs"

I know about user-homedir-pathname, but it's not quite convenient for interactive REPL use.

So I put together a short file that patches SBCL internals slightly so leading tildes in pathnames go through the POSIX getpw interface to look up home directories. It's not something I'll ever use in source files, but it's pretty convenient interactively.

To use it yourself, just download tilde.lisp and add this to your ~/.sbclrc:

(load "/path/to/tilde.lisp")
(tilde:install-tilde-expander)

After that, you can use "~/foo" and "~bob/foo" in SBCL pathnames.

update Here's a git repo for tilde.lisp, with an ASDF system file too.

Tags: lisp

xach

July 9 2008, 19:01:45 UTC 5 years ago

  • New comment
The reader must read the whole list starting with AND before evaluating it. There's a reason I put the commands in two different forms...

Anyway, if I were you, I'd use #+sbcl twice. Another option (that doesn't much appeal to me) is something like this:

#+sbcl
(when (load "tilde.lisp") (funcall (read-from-string "tilde:install-tilde-expander")))

Error

Anonymous comments are disabled in this journal

default userpic

Your reply will be screened

Your IP address will be recorded