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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:18:51+00:00 2026-05-19T01:18:51+00:00

I frequently find myself wanting to efficiently run a Clojure function multiple times with

  • 0

I frequently find myself wanting to efficiently run a Clojure function multiple times with an integer index (like “dotimes”) but also get the results out as a ready-made sequence/list (like “for”).

i.e. I’d like to do something like this:

(fortimes [i 10] (* i i))

=> (0 1 4 9 16 25 36 49 64 81)

Clearly it would be possible to do:

(for [i (range 10)] (* i i))

But I’d like to avoid creating and throwing away the temporary range list if at all possible.

What’s the best way to achieve this in Clojure?

  • 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-19T01:18:52+00:00Added an answer on May 19, 2026 at 1:18 am

    I’ve written an iteration macro that can do this and other types of iteration very efficiently. The package is called clj-iterate, both on github and clojars. For example:

    user> (iter {for i from 0 to 10} {collect (* i i)})
    (0 1 4 9 16 25 36 49 64 81 100)
    

    This will not create a temporary list.

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

Sidebar

Related Questions

I frequently find myself writing code like this: List<int> list = new List<int> {
I frequently find myself wanting to make a table of forms -- a bunch
I find that I frequently end up writing a function that I always call
I frequently find myself doing this: !(val).nil? My code would be prettier if there
I frequently find myself needing to apply a sequence of unary functions to a
I frequently find myself using the following pattern for string formatting. a = 3
I frequently find myself declaring a simple procedure type TMessageProc = procedure(const AMsg: String);
I frequently find myself creating classes which use this form (A): abstract class Animal
I frequently find myself writing utility classes that can be re-used throughout my projects.
I frequently find myself using setlocal within cmd.exe to avoid polluting the environment variable

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.