Hi Marco, 


---- On Sun, 14 Dec 2025 03:41:47 -0500 Marco Antoniotti <marco.antoniotti@unimib.it> wrote ---

Thanks Dave

Let me understand how this works....

If the file gets compiled (whatever invokes compile-file) the macro effectively freezes *compile-file-truename* in the code.  When I load the compiled file, that pathname is there, even if the compiled file now resides elsewhere.

If the file just gets loaded as source, then that's it and we do not have issues.

Did I get it right?

Nice.

MA



That is basically how I understand it is working, yes. 

And I think I got this originally from someone on #commonlisp IRC libera.chat when I was asking about this exact kind of stuff over there. A search of the logs for that channel might reveal who produced that nugget. 




On Sun, Dec 14, 2025 at 4:13 AM David Cooper <david.cooper@genworks.com> wrote:



--
Marco Antoniotti, Professor, Director         tel. +39 - 02 64 48 79 01
DISCo, University of Milan-Bicocca U14 2043   http://dcb.disco.unimib.it
Viale Sarca 336
I-20126 Milan (MI) ITALY

REGAINS: https://regains.disco.unimib.it/


Here is what according to me might be a portable way to catch the source pathname: 

```
 (defmacro source-pathname ()
  `,(or *compile-file-truename* *load-truename*))
```


Then at the top of your file that you want to know what was the source directory:


```
(defparameter *project-dir*
  (make-pathname :name nil :type nil :defaults (source-pathname)))

```

This source-pathname is a standard function or macro defined for Gendl in its so-called "glisp" portability layer.  I use that actual macro for SBCL because I couldn't find a built in thing to do it. Most of the other CLs have a built-in way e.g. Allegro's excl:*source-pathname* or CCL's ccl:*loading-file-source-file*. 

I think the macro should be portable though so maybe I should just be using it across the board.  



Dave Cooper


>
> On Sat, Dec 13, 2025 at 4:16 PM Marco Antoniotti <marco.antoniotti@unimib.it> wrote:
>>
>> Thanks but no.
>>
>> That would create a dependency from ASDF in the code.
>>
>> MA
>>
>>
>>
>> On Sat, Dec 13, 2025 at 1:50 PM Robert P. Goldman <rpgoldman@sift.net> wrote:
>>>
>>> ASDF:SYSTEM-RELATIVE-PATHNAME is probably what you want
>>> Sent from my iPhone
>>>
>>> > On Dec 13, 2025, at 06:11, Marco Antoniotti <marco.antoniotti@unimib.it> wrote:
>>> >
>>> > 
>>> > Hi
>>> >
>>> > I am getting old and I get confused.
>>> >
>>> > Here is the thing (a followup to the "wild" ASDF module question).
>>> >
>>> > I am writing something that will have, at run time, a variable *the-directory-where-stuff-is*.
>>> >
>>> > Now, I want to initialize this variable automagically, with no "outside" references.  I thought I could do something like
>>> >
>>> > (defvar the-directory-where-stuff-is*
>>> >    (merge-pathnames (make-pathname :directory '(:relative "stuff")
>>> >                                    :name nil :type nil)
>>> >                     (make-pathname :name nil :type nil
>>> >                                    :defaults *load-pathname*)))
>>> >
>>> > Alas, ASDF and other things may move the compiled file to a cache folder, which, in the end misaligns *load-pathname* w.r.t. where "stuff" actually is (and should be).
>>> >
>>> > This is something that build systems like cmake achieve with the notion of "source", "install", etc folders.
>>> >
>>> > Any ideas, suggestions, incantations, workarounds, even at the ASDF level to get this done?
>>> >
>>> > Thanks
>>> >
>>> >
>>> > --
>>> > Marco Antoniotti
>>>
>>
>>
>> --
>> Marco Antoniotti, Professor, Director         tel. +39 - 02 64 48 79 01
>> DISCo, University of Milan-Bicocca U14 2043   http://dcb.disco.unimib.it
>> Viale Sarca 336
>> I-20126 Milan (MI) ITALY
>>
>> REGAINS: https://regains.disco.unimib.it/
>
>
>
> --
> Marco Antoniotti, Professor, Director         tel. +39 - 02 64 48 79 01
> DISCo, University of Milan-Bicocca U14 2043   http://dcb.disco.unimib.it
> Viale Sarca 336
> I-20126 Milan (MI) ITALY
>
> REGAINS: https://regains.disco.unimib.it/