How to convert __source__.file to string?

Please understand the code, e.g. what each function does and why you need it, rather than blindly copying the code and trying things.

__source__.file is a Symbol. You basically want the macro to return it. For a normal value you’ll just return it directly but since macros handles a few syntax types (Expr, Symbol, etc) specially you need to stop it from doing that. That’s why you put it in a QuoteNode. In another word, that QuoteNode is there for the macro, not for the result.

That’s why you should not use QuoteNode before passing it to String. If anything, the QuoteNode should be on the String after you created it. It’s not necessary though since String isn’t a special syntax type.

AFAICT, what you want to do is exactly @__FILE__ so you can also find the answer by reading the source code of the macro, which you can find by searching for __FILE__ on github. Again, please understand it before using the implementation. If you don’t, feel free to ask here again about the “why” part.

1 Like