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 8047229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:02:21+00:00 2026-06-05T06:02:21+00:00

Context Currently, (println x is x) just prints out x is 10 Now, what

  • 0

Context

Currently,

(println "x is" x)

just prints out

x is 10

Now, what I want is something like this:

(my-println "x is" x)

to print out:

foo.clj:23> x is 10

Informally, I want my-println to append the _FILE_NAME_ and _LINE_NUMBER_ into my println.

Question:

I know how to use macros. However, I don’t know how to extract the _FILE_NAME_ and _LINE_NUMBER_ from the current location in Clojure (whereas C macros make this trivial to do). How do I get the current FILE_NAME_ and _LINE_NUMBER_ ?

Thanks.

  • 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-05T06:02:22+00:00Added an answer on June 5, 2026 at 6:02 am
    (defmacro my-println [x]
      `(do (printf "%s:%s> %s is %s\n"
                   ~*file*
                   ~(:line (meta &form))
                   ~(pr-str x)
                   ~x)
           (flush)))
    

    Looking at this answer again much later, you can be a bit more clever if you like, reducing the runtime costs by interpolating the string constants at compile time:

    (defmacro my-println [x]
      `(println ~(format "%s:%s> %s is"
                         *file*
                         (:line (meta &form))
                         (pr-str x))
                ~x))
    

    As you can see from the macroexpansion, there is no longer any need to invoke relatively-expensive printf code at runtime:

    (let [x 5] (macroexpand '(my-println (+ x 5))))
    (clojure.core/println "foo.clj:1> (+ x 5) is" (+ x 5))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently load my properties file like so in spring <context:property-placeholder location=test-esb-project-config.properties/> <context:property-placeholder location=esb-project-config.properties/>
So I currently have this code: (ns contact-form.core (:gen-class)) (def foo Hello World!) (defn
So I wanted to do something like this: @Component @Scope(value=request, proxyMode=ScopedProxyMode.INTERFACES) public class MyBean
If i want to get the external path like this, and device has Android
In Apress Pro Android 4 the author has said that: [...] context of currently
I am currently setting the connection string for my linq to sql data context
I currently register a content observer on the following URI content://sms/ to listen out
I am currently trying to stream content out to the web after a trans-coding
Currently I'm working on to display Epub content in UIWebview . From this link
In this program, how can break execution with the debugger and print the value

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.