Does Clojure have named arguments? If so, can you please provide a small example of it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
In Clojure 1.2, you can destructure the
restargument just like you would destructure a map. This means you can do named non-positional keyword arguments. Here is an example:Anything you can do while destructuring a Clojure map can be done in a function’s argument list as shown above. Including using :or to define defaults for the arguments like this:
But this is in Clojure 1.2. Alternatively, in older versions, you can do this to simulate the same thing:
and that works generally the same way.
And you can also have positional arguments that come before the keyword arguments:
These are not optional and have to be provided.
You can actually destructure the
restargument like you would any Clojure collection.You can do this sort of thing even in Clojure 1.1. The map-style destructuring for keyword arguments only came in 1.2 though.