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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:09:04+00:00 2026-05-26T09:09:04+00:00

We stumbled upon an issue in our code today, and couldn’t answer this Clojure

  • 0

We stumbled upon an issue in our code today, and couldn’t answer this Clojure question:

Does Clojure evaluate impure code (or calls to Java code) strictly or lazily?

It seems that side-effects + lazy sequences can lead to strange behavior.


Here’s what we know that led to the question:

Clojure has lazy sequences:

user=> (take 5 (range)) ; (range) returns an infinite list
(0 1 2 3 4)

And Clojure has side-effects and impure functions:

user=> (def value (println 5))
5                               ; 5 is printed out to screen
user=> value
nil                             ; 'value' is assigned nil

Also, Clojure can make calls to Java objects, which may include side-effects.
However, side-effects may interact poorly with lazy evaluation:

user=> (def my-seq (map #(do (println %) %) (range)))
#'user/my-seq
user=> (take 5 my-seq)                               
(0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
0 1 2 3 4)

So it returned the first 5 elements, but printed the first 31!

I assume the same kinds of problems could occur if calling side-effecting methods on Java objects. This could make it really hard to reason about code and figure out what’s going to happen.


Ancillary questions:

  • Is it up to the programmer to watch out for and prevent such situations? (Yes?)
  • Besides sequences, does Clojure perform strict evaluation? (Yes?)
  • 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-26T09:09:04+00:00Added an answer on May 26, 2026 at 9:09 am

    Clojure’s lazy seqs chunk about 30 items so the little overhead is further reduced. It’s not the purist’s choice but a practical one. Consult “The Joy of Clojure” for an ordinary solution to realize one element at time.

    Lazy seqs aren’t a perfect match for impure functions for the reason you encountered.

    Clojure will also evaluate strictly, but with macros things are a bit different. Builtins such as if will naturally hold evaluating.

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

Sidebar

Related Questions

Update : I just stumbled upon this in Eric Lippert's answer to another question
I stumbled upon this oddity today while playing with some code to go down
I got stumbled upon this issue once and I guess I need some expertise
I stumbled upon this code and I am curious as to what use may
I stumbled upon this question: 7 power 7 is 823543. Which higher power of
I've stumbled upon a rather strange issue today with Spring 3.0: There's an abstract
So I'm trying to install a web application and I stumbled upon this question:
I just stumbled upon this issue and i can't think of a solution I
I've stumbled upon this issue and my noob brain got fried trying to resolve
I stumbled upon this while doing a review and the author is not available:

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.