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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:34:07+00:00 2026-05-30T00:34:07+00:00

I asked a related question here: Clojure: How do I turn clojure code into

  • 0

I asked a related question here: Clojure: How do I turn clojure code into a string that is evaluatable? It mostly works but lists are translated to raw parens, which fails

The answer was great but I realized that is not exactly what I needed. I simplified the example for stackoverflow, but I am not just writing out datum, I am trying to write out function definitions and other things which contain structures that contain lists. So here is a simple example (co-opted from the last question).

I want to generate a file which contains the function:

(defn aaa []
  (fff :update {:bbb "bbb" :xxx [1 2 3] :yyy (3 5 7)}))

Everything after the :update is a structure I have access to when writing the file, so I call str on it and it emerges in that state. This is fine, but the list, when I load-file on this generated function, tries to call 3 as a function (as it is the first element in the list).

So I want a file which contains my function definition that I can then call load-file and call the functions defined in it. How can I write out this function with associated data so that I can load it back in without clojure thinking what used to be lists are now function calls?

  • 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-05-30T00:34:09+00:00Added an answer on May 30, 2026 at 12:34 am

    You need to quote the structure prior to obtaining the string representation:

    (list 'quote foo)
    

    where foo is the structure.

    Three additional remarks:

    1. traversing the code to quote all lists / seqs would not do at all, since the top-level (defn ...) form would also get quoted;

    2. lists are not the only potentially problematic type — symbols are another one (+ vs. #<core$_PLUS_ clojure.core$_PLUS_@451ef443>);

    3. rather than using (str foo) (even with foo already quoted), you’ll probably want to print out the quoted foo — or rather the entire code block with the quoted foo inside — using pr / prn.

    The last point warrants a short discussion. pr explicitly promises to produce a readable representation if *print-readably* is true, whereas str only produces such a representation for Clojure’s compound data structures “by accident” (of the implementation) and still only if *print-readably* is true:

    (str ["asdf"])
    ; => "[\"asdf\"]"
    
    (binding [*print-readably* false]
      (str ["asdf"]))
    ; => "[asdf]"
    

    The above behaviour is due to clojure.lang.RT/printString‘s (that’s the method Clojure’s data structures ultimately delegate their toString needs to) use of clojure.lang.RT/print, which in turn chooses output format depending on the value of *print-readably*.

    Even with *print-readably* bound to true, str may produce output inappropriate for clojure.lang.Reader‘s consumption: e.g. (str "asdf") is just "asdf", while the readable representation is "\"asdf\"". Use (with-out-str (pr foo)) to obtain a string object containing the representation of foo, guaranteed readable if *print-readably* is true.

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

Sidebar

Related Questions

I asked a related question here How do I programatically write parameters into the
I asked and answered a question here that is related to this issue and
I originally asked a related question here , but didn't really seem to get
This is related to a question I asked here: Thread Locking in Ruby (use
Related to a question I asked earlier here , I've found a problem which
This is a related to a previous question I have asked here, see the
I asked a related question about findbugs, but let's ask a more general question.
I asked a somewhat related question but I want it to make it more
I've asked a related question here: Show unmatched html tags in Notepad++ Having only
The related question has been asked here: CSS3 or jQuery animation with given step

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.