r/learnlisp • u/lispstudent • Jul 19 '24
How can my Common Lisp program know where it is running from?
I have been struggling to find a way for my Common Lisp program to know where it is running from, that is, the path where its image resides.
I know where the script is located when I write it. If I build an image and give it to a friend I lose that introspection. How does the image know where it will be put?
Finally I found this which seems to work:
(defvar *base-pathname* #.(or *compile-file-truename* *load-truename*))To me, this is just a magic incantation, specially the #. part. How does that work?
Is this the idiomatic way?
Many thanks in advance.
3
Upvotes
3
u/dzecniv Jul 19 '24
Hello, do you want
(uiop:getcwd)?By image do you imply binary?
1
u/zacque0 Jul 19 '24
This seems to work for me (on SBCL + Linux):
1
u/DefunHauter Jul 24 '24
only os knows all files opened by a progress, i guess there are some system calls can get the information. but it’s not the right way to implement normal requirements. tell more details about your features and why you want get the image location…