common lisp - get path to file
Asked Answered
P

5

14

In Common Lisp, is there a way to get the path to a compiled file (something like current-directory)?

The file is not inside the current-directory folder.

Propose answered 7/12, 2011 at 2:2 Comment(0)
R
14

This ought to be a comment but I'm going to give some code examples that might help the original poster along.

First of all, you need to be a little more clear about what you want to do. What is the problem you're trying to solve?

Secondly, here are a couple of examples which could be useful:

  • *default-pathname-defaults* usually set to the directory the CL image was started up in:

    * *default-pathname-defaults*
    #P"/Users/aerique/"
    
  • merge-pathnames allows you to construct new pathnames:

    * (merge-pathnames "lib/misc" *default-pathname-defaults*)
    #P"/Users/aerique/lib/misc"
    * (merge-pathnames "lib/misc/" *default-pathname-defaults*)
    #P"/Users/aerique/lib/misc/"
    
  • asdf:system-source-directory returns the path to a system loaded with ASDF:

    * (asdf:system-source-directory :linedit)  
    #P"/Users/aerique/quicklisp/dists/quicklisp/software/linedit-20111203-git/"
    

Also see the linked ASDF manual for more useful file and system functions.

Rodie answered 7/12, 2011 at 8:51 Comment(0)
M
9

*load-truename* resp. *load-pathname* gives you what you need.

http://www.lispworks.com/documentation/HyperSpec/Body/v_ld_pns.htm

Muscovado answered 6/10, 2013 at 11:24 Comment(0)
R
2

Perchance you want compile-file-pathname, which gives you the destination where compile-file would write into.

It'd help if you provide more context on what you're trying to achieve.

Rockling answered 7/12, 2011 at 11:22 Comment(0)
P
0

If you want get the pathname whitout use ASDF function, but you need also attend the users that use ASDF, you can use like this:

(defmacro project-pathname ()
  (let ((path (or *compile-file-pathname* *load-truename*)))
    `(progn ,path)))

It's necessary because the ASDF stores in one "/home/you/.../.cache/..." directory, and you need capture the pathname in compilation time with one macro.

Princely answered 15/12, 2019 at 14:11 Comment(0)
J
-2

You can use:

*default-pathname-defaults*

Please see http://cybertiggyr.com/gene/pathnames-0/node11.html

Joyner answered 7/12, 2011 at 9:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.