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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:05:05+00:00 2026-05-27T15:05:05+00:00

The clojure document gives the following examples: (take 10 (iterate (partial + 2) 0))

  • 0

The clojure document gives the following examples:

(take 10 (iterate (partial + 2) 0))

(def powers-of-two (iterate (partial * 2) 1))
(take 10 powers-of-two)

(def fib (map first (iterate (fn [[a b]] [b (+ a b)]) [1 1])))
(take 10 fib)

Anyone can explain the syntax of clojure’s iterate function in more detail? I am very confused with all the usage. Why two brackets are there in (fn [[a b]] [b (+ a b)])?

Another example can be found here:

(defn iter [[x y]]
  (vector y (+ x y)))

(nth (iterate iter [0 1]) 10000)
  • 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-27T15:05:06+00:00Added an answer on May 27, 2026 at 3:05 pm

    iterate takes a function f and an initial value x and produces a lazy sequence. The first element in the seq is x. Each subsequent element is computed by calling f with the previous element.

    Example 1:

    (iterate (partial + 2) 0)
    

    This generates a sequence, starting at 0, where each element is the previous element with 2 added to it. I.e.:

    0
    (+ 2 0) ; => 2
    (+ 2 2) ; => 4
    (+ 2 4) ; => 6
    ; etc
    

    Each element in the seq is passed to (partial + 2) when generating the following element.

    Example 2:

    (iterate (partial * 2) 1)
    

    This generates a sequence, starting at 1, where each element is the previous element multiplied by 2. I.e.:

    1
    (* 2 1) ; => 2
    (* 2 2) ; => 4
    (* 2 4) ; => 8
    (* 2 8) ; => 16
    ; etc
    

    Again, you can see how each element feeds into the generation of the next one.

    Example 3:

    (iterate (fn [[a b]] [b (+ a b)]) [1 1])
    

    Firstly, (fn [[a b]] ...) is a way to destructure a value into parts. In this case, the function accepts a two-element vector and unpacks it into the local variables a and b.

    The function returns a two-element vector containing b and the sum of a and b (i.e. the second value in the previous pair and the sum of both values in the previous pair).

    With this in mind, this iterate call generates:

    [1 1]
    [1 (+ 1 1)] ; => [1 2]
    [2 (+ 1 2)] ; => [2 3]
    [3 (+ 2 3)] ; => [3 5]
    [5 (+ 3 5)] ; => [5 8]
    ; etc
    

    Then (map first ...) grabs the first value in each pair, which gives you your Fibonacci sequence.

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

Sidebar

Related Questions

In clojure, keywords evaluate to themselves, e.g.: >>:test :test They don't take any parameters,
In Clojure, I want to combine two lists to give a list of pairs,
I have the following Clojure code and I'm not sure why it's not working:
In C#, please does anyone know why I can't do the following? (specifically the
I'd like some help with the following jQuery code if possible... $(document).ready(function() { $('table.sortable').each(function()
The structure of my hash is (def *document-hash* {documentid {:term-detail {term1 tf1 ,term2 tf2}})
In Clojure, what is the best way for iterating concurrently on two seqs and
Clojure structs can be arbitrarily extended, adding new fields. Is it possible to extend
in clojure i have vector [myfn1 myfn2 myfn3] how can i call functions named
Clojures clojure.xml/parse, clojure.zip/xml-zip and clojure.contrib.zip-filter.xml/xml-> are excellent tools for pulling values out of xml,

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.