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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:11:49+00:00 2026-06-18T15:11:49+00:00

Examples of Clojure arity-overloading on functions like the following (taken from the cookbook ):

  • 0

Examples of Clojure arity-overloading on functions like the following (taken from the cookbook):

(defn argcount
  ([] 0)                                ; Zero arguments
  ([x] 1)                               ; One argument
  ([ x &  args] (inc (count args))))    ; List of arguments

… use a form that doesn’t seem to allow the functions of lower arity to simply call the functions of higher arity with some default values (that’s a common idiom in Java).
Is some other special form used for that ?

  • 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-18T15:11:50+00:00Added an answer on June 18, 2026 at 3:11 pm

    There’s usually a good way to express the higher arity arguments in a way that doesn’t need to refer to other arities using higher order functions and map / reduce. In this case it’s pretty simple:

    (defn argcount
      ([] 0)
      ([x] 1)
      ([x & args]
        (reduce + 1 (map (constantly 1) args))))
    

    Notice the general form of the expression is:

    (reduce reducing-function arity-1-value (map mapping-function rest-of-args))
    

    You can’t do everything this way, but this works for a surprisingly large proportion of multi-argument functions. It also gains the advnatages of laziness using map, so you can do crazy things like pass ten million arguments to a function with little fear:

    (apply argcount (take 10000000 (range)))
    => 10000000
    

    Try that in most other languages and your stack will be toast 🙂

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

Sidebar

Related Questions

I'm following the examples from the book 'Programming Clojure', and I'm at page 17
I've created file hello.clj (ns clojure.examples.hello (:gen-class)) (defn -main [greetee] (println (str Hello greetee
So following on from Clojure macro to create a synonym for a function ,
I am trying to understand Clojure futures, and I've seen examples from the common
Working on the following example in Clojure in Action (p. 63): (defn basic-item-total [price
The clojure document gives the following examples: (take 10 (iterate (partial + 2) 0))
I'm working through the Clojure examples in Stuart Halloway's Programmming Clojure and I've hit
What I would like to do (in Clojure): For example, I have a vector
Does clojure have a powerful 'loop' like common lisp. for example: get two elements
VB examples please I need to return the same results from linq as I

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.