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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:25:16+00:00 2026-06-03T17:25:16+00:00

(take 2 (for [x (range 10) :let [_ (println x)] :when (even? x)] x))

  • 0
(take 2 (for [x (range 10)
              :let [_ (println x)]
              :when (even? x)] x))
>> (* 0
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
0 2)

I assumed I was just being remarkably dense. But no, it turns out that Clojure actually evaluates the first 32 elements of any lazy sequence (if available). Ouch.

I had a for with a recursive call in the :let. I was very curious as to why computation seemed to be proceeding in a breadth first rather than depth first fashion. It seems that computation (although, to be fair, not memory) was exploding as I kept going down all the upper branches of the recursive tree. Clojure’s 32-chunking was forcing breadth first evaluation, even though the logical intent of the code was depth first.

Anyway, is there any simple way to force 1-chunking rather than 32-chunking of lazy sequences?

  • 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-03T17:25:18+00:00Added an answer on June 3, 2026 at 5:25 pm

    Michaes Fogus has written a blog entry on disabling this behavior by providing a custom ISeq implementation.

    To steal shamelessly from the modified version by Colin Jones:

    (defn seq1 [#^clojure.lang.ISeq s]
      (reify clojure.lang.ISeq
        (first [_] (.first s))
        (more [_] (seq1 (.more s)))
        (next [_] (let [sn (.next s)] (and sn (seq1 sn))))
        (seq [_] (let [ss (.seq s)] (and ss (seq1 ss))))
        (count [_] (.count s))
        (cons [_ o] (.cons s o))
        (empty [_] (.empty s))
        (equiv [_ o] (.equiv s o))))
    

    A simpler approach is given in The Joy of Clojure:

    (defn seq1 [s]
      (lazy-seq
        (when-let [[x] (seq s)]
           (cons x (seq1 (rest s))))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take this example code (ignore it being horribly inefficient for the moment) let listToString
Let us take this example scenario: There exists a really complex function that involves
Can anyone give me VBA code that will take a range (row or column)
I have a function that will take a range of values, which need to
I think, it is easier explain using an example. Let's take a class that
I'm trying to define a command that can take a range and pass it
I'm trying to create a function so that =processCells(A1:A10) will take the range of
All I am trying to do is take a standard range on an excel
I'm working on an application in Clojure that needs to multiply large matrices and
Just want to ensure you that it is not a homework question. I am

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.