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

The Archive Base Latest Questions

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

I have some Clojure code that seems maddeningly simple and yet is throwing an

  • 0

I have some Clojure code that seems maddeningly simple and yet is throwing an IllegalArgumentException. For reference, the following code shows 4 functions I have been coding. My error lies in the 4th.

"Determine candy amount for first parameter. Returns even integers only (odd #'s rounded up)."
(defn fun1 [x y] (if (= (rem (+ (quot x 2) (quot y 2)) 2) 1) (+ (+ (quot x 2) (quot y 2)) 1) (+ (quot x 2) (quot y 2))))

"Play one round. Returns vector with new values."
(defn fun2 [[x y z t]] (vector (fun1 x z) (fun1 y x) (fun1 z y) (+ t 1)))

"Yield infinite sequence of turns."
(defn fun3 [[x y z t]] (if (= x y z) (vector x y z t) (iterate fun2 [x y z t])))

(defn fun4 [[x y z t]] (take-while #(not= %1 %2 %3) (fun3 [x y z t])))

The fourth function calls the 3rd function until the values x y and z are not equal. The code compiles correctly yet I get the following sequence in the REPL:

Clojure 1.1.0
user=> (load-file "ass8.clj")
#'user/fun4
user=> (fun4 [10 10 10 1])
java.lang.IllegalArgumentException: Wrong number of args passed to: user$fun4--21$fn
(user=> (fun4 [[10 10 10 1]])
java.lang.IllegalArgumentException: Wrong number of args passed to: user$fun4--21$fn
(user=> (fun4 10 10 10 1)
java.lang.IllegalArgumentException: Wrong number of args passed to: user$fun4 (NO_SOURCE_FILE:0)

Only the first expression is really correct, but I’m making the point that I’ve tried all possible combinations. Can anyone shed some light on this mysterious error? Possibly test it in your own Clojure environment..?

As a side note, shouldn’t fun3 stop when x = y = z? It seems to give an infinite sequence now so the if seems superfluous.

  • 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-26T19:47:51+00:00Added an answer on May 26, 2026 at 7:47 pm

    As par your comment above you can use below code (Use existing code for fun1)

    (defn fun2 [v] 
            (loop [[a b c d] v] 
                  (if (= a b c) 
                      [a b c d] 
                  (recur [(fun1 a c) (fun1 b a) (fun1 c b) (+ d 1)]))))
    

    You don’t really need fun3 and fun4

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

Sidebar

Related Questions

I have some Clojure code that is simulating and then processing numerical data. The
I'm working on some Clojure code that has some circular dependencies between different namespaces
I have a group of numeric functions in Clojure that I want to validate
I have the following Clojure code to calculate a number with a certain factorable
I have a bunch of functions that map to and from some codes defined
So I have defined some vars to hold state data in my clojure code.
I have some UI in VB 2005 that looks great in XP Style, but
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
We have some input data that sometimes appears with &nbsp characters on the end.
I have some C# / asp.net code I inherited which has a textbox which

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.