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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:13:48+00:00 2026-06-03T21:13:48+00:00

Note: Not a duplicate of Why does Clojure recur think it should only have

  • 0

Note: Not a duplicate of Why does Clojure recur think it should only have one argument?. I’m not using a loop.

(def t 
  #(let [[low high] (sort %&)] {:low low :high h}))

(t 3 2)
=> {:low 2, :high 3}

Given that this works as expected. How come this doesn’t:

(def t 
  #(let [[low high] (sort %&)] 
    (if (= 0 low)
      nil
      (do
        (println {:low low :high high})
        (recur low (dec high))))))

(t 3 2)
=> java.lang.IllegalArgumentException: Mismatched argument count to recur, expected: 1 args, got: 2

Given that it says that it is expecting 1 argument I can guess that I can make it work by turning the arguments into a collection:

(def t
  #(let [[low high] (sort %&)]
    (if (= 0 low)
      nil
      (do
        (println {:low low :high high})
        (recur [low (dec high)])))))

(t 3 2)
=> {:low 2, :high 3}
   {:low 2, :high 2}
   {:low 1, :high 2}
   {:low 1, :high 1}
   nil

… but why?

  • 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-03T21:13:50+00:00Added an answer on June 3, 2026 at 9:13 pm

    This is just how it was designed. The Clojure website says:

    The recur expression must match the arity of the recursion point exactly. In particular, if the recursion point was the top of a variadic fn method, there is no gathering of rest args – a single seq (or null) should be passed.

    I presume it was designed this way because if the function itself is giving you a sequence (and not individual arguments) then it would be more natural for the recur form to instead accept a sequence, or something that can become a sequence. If this was not the case, you would then need to break apart the given sequence in order to perform the recursion.

    Your example doesn’t seem to fit the mold because it looks like you really only care about having two arguments, which means you really don’t need the rest args. You would probably be better off explicitly defining the two arguments and determining which is low and high in the let statement, instead of sorting the rest args and destructuring them.

    Here’s your code with minimal modification. I wrapped the two explicit arguments in a vector before passing them into sort (essentially mimicing rest args), and passed two arguments into recur.

    (def t
      #(let [[low high] (sort [%1 %2])]
        (if (= 0 low)
          nil
          (do
            (println {:low low :high high})
            (recur low (dec high))))))
    

    However, while keeping the recur form, I would probably refactor this a little bit:

    (defn t [x y]
      (let [low (min x y) high (max x y)]
        (when-not (zero? low)
          (println {:low low :high high})
          (recur low (dec high)))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C++, how do I combine (note: not add) two integers into one big
I wrote a custom control inherited from WebControl. (Note: not a user control). using
Note - I do not have access to a database and cannot use PHP,
Please note this is not duplicate of File r/w locking and unlink . (The
Follow-up question to this question : (note that this is not a duplicate, I'm
-getcwd does not return it at least when debugging with VS 2010. -i have
Note: this is not real information: $ ssh-keygen -t rsa -C "tekkub@gmail.com" Generating public/private
Note: I'm not a newb, and I've done this a gazillion times, but for
Note: I am not exactly sure what to name the question, so if someone
Note: this is NOT about concurrency. This is about the thread macro. I know

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.