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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:21:23+00:00 2026-06-10T02:21:23+00:00

I have several strings: (def a some random string) (def b this is a

  • 0

I have several strings:

(def a "some random string")
(def b "this is a text")

Now i want to concatenate parts of them to create a string “some text”. Unfortunately both of the strings below didn’t work.

(clojure.string/join " " [(take 4 a) (take-last 4 b)])
(str (take 4 a) " " (take-last 4 b))

It’s because functions take and take-last return lazy sequences. The question is: what is the proper way to concatenate multiple lazy sequences of strings and return one string?

Edit: I found one solution – (apply str (concat (take 4 a) " " (take-last 4 a))) – but is it the most correct way?

  • 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-10T02:21:25+00:00Added an answer on June 10, 2026 at 2:21 am

    Rather than using sequence functions to slice the input strings, you might want to use the much more efficient subs (for substring; note there’s a GC-related caveat about it, see below):

    (subs "asdf" 1 2)
    ; => "s"
    
    ;; a and b as in the question text
    (clojure.string/join " " [(subs a 0 4) (subs b (- (count b) 4))])
    ; => "some text"
    

    The aforementioned caveat is that as long as the "s" returned in the first example here remains ineligible for garbage collection, so does the original "asdf" (since subs returns a “view” onto the input String without allocating fresh storage — this is the behaviour of Java’s substring method which subs wraps). This is not a problem if you immediately hand the "s" off to subs and retain no other reference to it, since join will discard it after pulling the characters.

    If you do end up working with lazy sequences of characters after all, there’s nothing to be done but to use something like (map (partial apply str) [...your vector here...]) to turn the inputs to clojure.string/join into strings.

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

Sidebar

Related Questions

I have an object with several text strings as members. I want to write
I have several strings in the rough form: [some text] [some number] [some more
I have several strings that will be replaced with the same string... ie $text=str_ireplace('[/VIDEO]','</div>',$text);
I have several thousand text strings where the IMDB occures in fairly random positions,
I have a situation where I need to concatenate several string to form an
I have a several processes node.js. I want to only add one string to
I have a Python function accepting several string arguments def foo(a, b, c): and
i have several strings that look like this: contactBtn, programBtn, cartBtn. How can i
I have several strings that I need to parse. The string is supposed to
I have a String made up of several Strings seperated by commas. Using StringTemplate,

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.