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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:50:56+00:00 2026-05-26T07:50:56+00:00

1) (def x (for [i (range 1 3)] (do (println i) i))) 2) (def

  • 0

1) (def x (for [i (range 1 3)] (do (println i) i)))

2) (def x (for [i (range 1 3)] (do i)))

Both produces same output, then what is the use of println?

  • 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-26T07:50:57+00:00Added an answer on May 26, 2026 at 7:50 am

    Values evaluate to themselves, and a do block returns the result of the last expression. That is why (do 2) returns 2, in the example below. Because it returns 2, when evalled from a REPL, 2 will be printed to the screen as the result.
    The function println however causes a side effect, but returns nil. The side effect below is that the value 2 will be printed to standard output. Also nil is printed, because that is the return value from the function println.

    user=> (do 2)
    2
    user=> (println 2)
    2
    nil
    

    In your example the outputs are not the same, because of what I explained above. Notice the difference yourself:

    user=> (def x (for [i (range 1 3)] (do (println i) i)))
    #'user/x
    user=> x
    (1
    2
    1 2)
    user=> (def x (for [i (range 1 3)] (do i)))
    #'user/x
    user=> x
    (1 2)
    

    Also take note that for is lazy:

    (def x (for [i (range 1 3)] (do (println i) i)))
    #'user/x
    user=> x
    (1
    2
    1 2)
    user=> x
    (1 2)
    

    The second time x is requested, only (1 2) is printed. Why? Because for is lazy. It only produces its elements the first time they are requested (the first time x is requested). A next time, the elements are already produced, so the side effect within do will not happen again.

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

Sidebar

Related Questions

My function is def validate_latitude(lat): Enforce latitude is in range >>> validate_latitude(65) 65 >>>
def partial(template, *args) options = args.extract_options! options.merge!(:layout => false) if collection = options.delete(:collection) then
I have a function in python whose output is a generator : def main_function(x):
def fun1(a): for i in range(len(a)): a[i] = a[i] * a[i] return a
Look at this simple function def prime_factors(n): for i in range(2,n): if n %
def pi(times): seq = [] counter = 0 for x in range(times): counter +=
def different(s): x = len(s) for i in range(1, 1 << x): u.append([s[j] for
consider the following code: class MyClass(object): def __init__(self): self.data_a = np.array(range(100)) self.data_b = np.array(range(100,200))
Look at the following Python code: def function(x): return x, x+1 sequence = range(5)
Below is a program in Scala. def range(low : Int, high : Int) :

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.