Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8612713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:41:44+00:00 2026-06-12T04:41:44+00:00

I’m reading in the API docs that the *file* variable should have a value

  • 0

I’m reading in the API docs that the *file* variable should have a value of “the path of the file being evaluated, as a String”. However, this feature seems broken in certain cases.

When I execute a file using lein exec, things work as expected:

$ cat test.clj
(println *file*)
$ lein exec test.clj 
/path/to/test.clj

Yet when I run a test that contains a call to (println *file*), NO_SOURCE_PATH is printed instead of the file containing that line.

Why am I seeing this behavior, and how can I reliably access the path and filename of the file being evaluated?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:41:45+00:00Added an answer on June 12, 2026 at 4:41 am

    *file* is set to the path of the file being compiled, so after your whole program is compiled it is no longer useful to look at the value of *file* (assuming no use of eval).

    In your test.clj example, the println is executed while the file is still being compiled. If the reference to *file* is moved into a test or function, it will only be dereferenced at runtime after the value of *file* is no longer useful.

    One option is to write a macro that stores the value of *file* when it is expanded, so that the result can be used later. For example, a file example.clj could have:

    (defmacro source-file []
      *file*)
    
    (defn foo [x]
      (println "Foo was defined in" (source-file) "and called with" x))
    

    Then from the REPL or anywhere, (foo 42) would print:

    Foo was defined in /home/chouser/example.clj and called with 42
    

    Note that it doesn’t matter which file source-file is defined in, only where it was expanded, that is the file where foo is defined. This works because it’s when foo is compiled that source-file is run, and the return value of source-file which is just a string is then included in the compiled version of foo. The string is then of course available every time foo executes.

    If this behaviour is surprising, it may help to consider what would have to happen in order for *file* to have a useful value inside every function at runtime. Its value would have to change for every function call and return, a substantial runtime overhead for a rarely-used feature.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.