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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:09:01+00:00 2026-05-26T11:09:01+00:00

How does Clojure determine how many arguments an anonymous function (created with the #…

  • 0

How does Clojure determine how many arguments an anonymous function (created with the #... notation) expect?

user=> (#(identity [2]) 14)
java.lang.IllegalArgumentException: Wrong number of args (1) passed to: user$eval3745$fn (NO_SOURCE_FILE:0)
  • 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-26T11:09:02+00:00Added an answer on May 26, 2026 at 11:09 am

    #(println "Hello, world!") -> no arguments

    #(println (str "Hello, " % "!")) -> 1 argument (% is a synonym for %1)

    #(println (str %1 ", " %2 "!")) -> 2 arguments

    and so on. Note that you do not have to use all %ns, the number of arguments expected is defined by the highest n. So #(println (str "Hello, " %2)) still expects two arguments.

    You can also use %& to capture rest args as in

    (#(println "Hello" (apply str (interpose " and " %&))) "Jim" "John" "Jamey").

    From the Clojure docs:

    Anonymous function literal (#())
    #(...) => (fn [args] (...))
    where args are determined by the presence of argument literals taking the 
    form %, %n or  %&. % is a synonym for %1, %n designates the nth arg (1-based), 
    and %& designates a rest arg. This is not a replacement for fn - idiomatic 
    used would be for very short one-off mapping/filter fns and the like. 
    #() forms cannot be nested.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does Clojure specify the order of evaluation of function arguments? I.e. When I call
Does Clojure have named arguments? If so, can you please provide a small example
Does anybody want to answer my question linked here how-to-pass-a-typed-collection-from-clojure-to-java , by providing a
From Clojure it is easy enough to use Java libraries...but what libraries does Clojure
clojure / src / jvm / clojure / lang / RT.java The above seems
I understand that you can easily mix groovy&java, clojure&java, whateverJvmLang&java. Does this also mean
Why does the following Clojure program throw a NullPointerException? user=> (defn x [] Do
Does the Java language have delegate features, similar to how C# has support for
does anyone know of a good profiling tool or library for Clojure? I would
How does JVM type erasure help Clojure? Can Clojure exist without it? What would

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.