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

  • Home
  • SEARCH
  • 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 1001703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:43:05+00:00 2026-05-16T07:43:05+00:00

I have a string containing a valid Clojure form. I want to replace a

  • 0

I have a string containing a valid Clojure form. I want to replace a part of it, just like with assoc-in, but processing the whole string as tokens.

=> (assoc-in [:a [:b :c]] [1 0] :new)
[:a [:new :c]]
=> (assoc-in [:a 
                [:b,, :c]] [1 0] :new)
[:a [:new :c]]
=> (string-assoc-in "[:a 
                       [:b,, :c]]" [1 0] ":new")
"[:a 
   [:new,, :c]]"

I want to write string-assoc-in. Note that its first and last arguments are strings, and it keeps the line break and the commas. Is it doable in Clojure? The closest thing I found is read which calls clojure.lang.LispReader, but I don’t know how works.

I want to use it to read a Clojure source file and display it with some modifications, keeping the structure of the file.

  • 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-16T07:43:05+00:00Added an answer on May 16, 2026 at 7:43 am

    I think this should work, be entirely general and not require its own reader / parser:

    (defn is-clojure-whitespace? [c]
      (or (Character/isSpace c)
          (= \, c)))
    
    (defn whitespace-split
      "Returns a map of true -> (maximal contiguous substrings of s
      consisting of Clojure whitespace), false -> (as above, non-whitespace),
      :starts-on-whitespace? -> (whether s starts on whitespace)."
      [s]
      (if (empty? s)
        {}
        (assoc (group-by (comp is-clojure-whitespace? first)
                         (map (partial apply str)
                              (partition-by is-clojure-whitespace? s)))
          :starts-on-whitespace?
          (if (is-clojure-whitespace? (first s)) true false))))
    
    (defn string-assoc-in [s coords subst]
      (let [{space-blocks true
             starts-on-whitespace? :starts-on-whitespace?}
            (whitespace-split s)
            s-obj (assoc-in (binding [*read-eval* false] (read-string s))
                            coords
                            (binding [*read-eval* false] (read-string subst)))
            {non-space-blocks false}
            (whitespace-split (pr-str s-obj))]
        (apply str
               (if starts-on-whitespace?
                 (interleave space-blocks (concat non-space-blocks [nil]))
                 (interleave non-space-blocks (concat space-blocks [nil]))))))
    

    Example:

    user> (string-assoc-in "[:a [:b,, :c]]" [1 0] ":new")
    "[:a [:new,, :c]]"
    

    Update: Ouch, caught a bug:

    user> (string-assoc-in "[:a [:b,, :c\n]]" [1 0] ":new")
    "[:a [:new,, :c]]\n"
    

    I’d love it if it didn’t matter, but I guess I’ll have to try and do something about it… sigh

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

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you want to get the values back into the… May 16, 2026 at 4:51 pm
  • Editorial Team
    Editorial Team added an answer If you want to use jetty maven plugin <plugin> <groupId>org.mortbay.jetty</groupId>… May 16, 2026 at 4:51 pm
  • Editorial Team
    Editorial Team added an answer ProcessStartInfo.Verb will only have an effect if the process is… May 16, 2026 at 4:51 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a variable containing a string Y.Plugin.abcd and I would like to access
I'm using python, and I want a function that takes a string containing a
Similar to this thread for C# , I need to split a string containing
I have (in D2010) a TDrawGrid on my form. Im handling my OnDrawCell, OnSetEditText,
I have a string in an Android app that I am trying to convert
i am trying to build up a string containing the values of fields in
I need to convert a collection of <string,string> to a single string containing all
I have a script file containing 1000 lines of data and some of the
I have a JavaScript containing a text-input and some placeholders. The script uses a
If I have a function like this: function foo() { //... return false; }

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.